List of usage examples for com.fasterxml.jackson.databind.type TypeFactory defaultInstance
public static TypeFactory defaultInstance()
From source file:com.infinities.nova.util.jackson.ObjectMapperResolver.java
public ObjectMapperResolver() { objectMapper = new ObjectMapper(); AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()); AnnotationIntrospector secondary = new JacksonAnnotationIntrospector(); objectMapper = objectMapper/* w w w. ja v a2s. c om*/ .setAnnotationIntrospector(new AnnotationIntrospectorPair(introspector, secondary)); objectMapper = objectMapper.enable(SerializationFeature.INDENT_OUTPUT); objectMapper = objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true); objectMapper.registerModule(new Hibernate4Module()); }
From source file:com.cosmicpush.jackson.PushJacksonResolver.java
@Override public JavaType typeFromId(DatabindContext context, String id) { PushType pushType = PushType.find(id); return TypeFactory.defaultInstance().uncheckedSimpleType(pushType.getType()); }
From source file:com.github.cjm.service.BaseService.java
public ResourceCollection load(String resource, Class clazz, int page) { StringBuilder uri = new StringBuilder(MOVIEDB_URL); uri.append(resource);/*from ww w . j ava 2s .c o m*/ uri.append("?api_key=").append(apiKey); if (page > 1) { uri.append("&page=").append(page); } RestTemplate restTemplate = new RestTemplate(); ResourceCollection<T> resourceCollection = new ResourceCollection<>(); String data = null; try { data = restTemplate.getForObject(uri.toString(), String.class); } catch (HttpClientErrorException e) { log.warn(e.getMessage()); } if (data != null) { ObjectMapper mapper = new ObjectMapper(); try { TypeFactory t = TypeFactory.defaultInstance(); resourceCollection = mapper.readValue(data, t.constructType(clazz)); } catch (IOException ex) { log.error("ObjectMapper exception: ", ex); } } return resourceCollection; }
From source file:com.infinities.keystone4j.utils.jackson.ObjectMapperResolver.java
public ObjectMapperResolver() { objectMapper = new ObjectMapper(); AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()); AnnotationIntrospector secondary = new JacksonAnnotationIntrospector(); objectMapper = objectMapper//from w w w .ja v a 2 s . co m .setAnnotationIntrospector(new AnnotationIntrospectorPair(introspector, secondary)); objectMapper = objectMapper.enable(SerializationFeature.INDENT_OUTPUT); objectMapper.registerModule(new Hibernate4Module()); }
From source file:lab.mage.rate.example.NewsFeedRobot.java
@Override public void start(long lifetime, RequestProcessor requestProcessor) { final long callADay = System.currentTimeMillis() + lifetime; while (callADay > System.currentTimeMillis()) { final Response responseGetAll = requestProcessor.call("news", Request.type(Request.Type.GET).build()); List<News> foundNews = null; try {/* w w w. ja v a2 s . c om*/ foundNews = this.mapper.readValue(responseGetAll.getJson(), TypeFactory.defaultInstance().constructCollectionType(List.class, News.class)); } catch (IOException e) { e.printStackTrace(); } try { Thread.sleep(TimeUnit.SECONDS.toMillis(2L)); } catch (InterruptedException e) { // do nothing } final Response responseNews = requestProcessor.call( "news/" + (foundNews != null ? (foundNews.size() / 3) : 3), Request.type(Request.Type.GET).build()); try { Thread.sleep(TimeUnit.SECONDS.toMillis(10L)); } catch (InterruptedException e) { // do nothing } final News news = new News(); news.setTopic(Thread.currentThread().getName()); news.setTimeStamp(new Date(System.currentTimeMillis())); news.setText("No news are good news!"); try { final Response responseCreated = requestProcessor.call("news", Request.type(Request.Type.POST).json(mapper.writeValueAsString(news)).build()); } catch (JsonProcessingException e) { e.printStackTrace(); } try { Thread.sleep(TimeUnit.SECONDS.toMillis(5L)); } catch (InterruptedException e) { // do nothing } if (foundNews != null) { try { final News news2update = foundNews.get(foundNews.size() - 1); news2update.setText("Here are some good news!"); final Response responseUpdated = requestProcessor.call("news/" + news2update.getId(), Request.type(Request.Type.PUT).json(mapper.writeValueAsString(news2update)).build()); } catch (JsonProcessingException e) { e.printStackTrace(); } } try { Thread.sleep(TimeUnit.SECONDS.toMillis(7L)); } catch (InterruptedException e) { // do nothing } if (foundNews != null && foundNews.size() > 200) { final News news2delete = foundNews.get(foundNews.size() / 2); final Response responseDeleted = requestProcessor.call("news/" + news2delete.getId(), Request.type(Request.Type.DELETE).build()); } try { Thread.sleep(TimeUnit.SECONDS.toMillis(3L)); } catch (InterruptedException e) { // do nothing } } }
From source file:com.github.jasonruckman.sidney.core.type.Types.java
public static JavaType type(Type type) { return TypeFactory.defaultInstance().constructType(type); }
From source file:com.ning.billing.recurly.model.RecurlyObject.java
public static XmlMapper newXmlMapper() { final XmlMapper xmlMapper = new XmlMapper(); xmlMapper.setSerializerProvider(new RecurlyXmlSerializerProvider()); final AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); final AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()); final AnnotationIntrospector pair = new AnnotationIntrospectorPair(primary, secondary); xmlMapper.setAnnotationIntrospector(pair); xmlMapper.registerModule(new JodaModule()); xmlMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); final SimpleModule m = new SimpleModule("module", new Version(1, 0, 0, null, null, null)); m.addSerializer(Accounts.class, new RecurlyObjectsSerializer<Accounts, Account>(Accounts.class, "account")); m.addSerializer(AddOns.class, new RecurlyObjectsSerializer<AddOns, AddOn>(AddOns.class, "add_on")); m.addSerializer(Adjustments.class, new RecurlyObjectsSerializer<Adjustments, Adjustment>(Adjustments.class, "adjustment")); m.addSerializer(Coupons.class, new RecurlyObjectsSerializer<Coupons, Coupon>(Coupons.class, "coupon")); m.addSerializer(Invoices.class, new RecurlyObjectsSerializer<Invoices, Invoice>(Invoices.class, "invoice")); m.addSerializer(Plans.class, new RecurlyObjectsSerializer<Plans, Plan>(Plans.class, "plan")); m.addSerializer(RecurlyErrors.class, new RecurlyObjectsSerializer<RecurlyErrors, RecurlyError>(RecurlyErrors.class, "error")); m.addSerializer(SubscriptionAddOns.class, new RecurlyObjectsSerializer<SubscriptionAddOns, SubscriptionAddOn>(SubscriptionAddOns.class, "subscription_add_on")); m.addSerializer(Subscriptions.class, new RecurlyObjectsSerializer<Subscriptions, Subscription>(Subscriptions.class, "subscription")); m.addSerializer(Transactions.class, new RecurlyObjectsSerializer<Transactions, Transaction>(Transactions.class, "transaction")); xmlMapper.registerModule(m);//from w ww . j a v a 2s.com return xmlMapper; }
From source file:com.concentricsky.android.khanacademy.data.remote.KAEntityCollectionFetcherTask.java
public KAEntityCollectionFetcherTask(Class<T> type, String url) { this.url = url; TypeFactory f = TypeFactory.defaultInstance(); // this.type = new TypeReference<List<T>>() {}; // this.type = f.constructParametricType(ArrayList.class, type); this.type = f.constructCollectionType(ArrayList.class, type); }
From source file:com.abiquo.bond.api.AbiquoObjectMapper.java
private AbiquoObjectMapper() { objectMapper = new ObjectMapper().setAnnotationIntrospector( // new AnnotationIntrospectorPair(new JacksonAnnotationIntrospector(), new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()))) // .registerModule(new AbiquoModule()); }
From source file:org.tiogasolutions.jobs.jackson.JobActionJacksonResolver.java
@Override public JavaType typeFromId(DatabindContext context, String id) { ActionType actionType = ActionType.valueOf(id); try {//from w ww . ja v a 2 s .c om Class type = Class.forName(actionType.getTypeName()); return TypeFactory.defaultInstance().uncheckedSimpleType(type); } catch (ClassNotFoundException e) { String msg = String.format("The action type %s's implementing type %s was not found", actionType, actionType.getTypeName()); throw new UnsupportedOperationException(msg); } }