/** * {@inheritDoc} */ public CustomObjectMapper() { super(); this.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); this.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false); this.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false); this.setSerializationInclusion(JsonSerialize.Inclusion.NON_DEFAULT); this.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL); this.setSerializationInclusion(JsonSerialize.Inclusion.NON_EMPTY); final AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(); // make deserializer use JAXB annotations (only) this.setAnnotationIntrospector(introspector); // TODO leverage NamingStrategy to make reponse attributes more Java-like //this.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); }
public JsonModelSerializer(boolean doNullValues, Class<T> serializedType) { super(); objectMapper = new ObjectMapper(); AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(); // make serializer use JAXB annotations (only) SerializationConfig sc = objectMapper.getSerializationConfig().withAnnotationIntrospector(introspector); sc.with(SerializationConfig.Feature.INDENT_OUTPUT); if (!doNullValues) { sc.without(SerializationConfig.Feature.WRITE_NULL_MAP_VALUES); sc.without(SerializationConfig.Feature.WRITE_EMPTY_JSON_ARRAYS); sc = sc.withSerializationInclusion(Inclusion.NON_EMPTY); } objectMapper.setSerializationConfig(sc); // if (!doNullValues) { // objectMapper.setSerializationInclusion(Inclusion.NON_EMPTY); // } }
private String buildJson(Object object) { ObjectMapper mapper = new ObjectMapper(); SerializationConfig serializationConfig = mapper.getSerializationConfig(); serializationConfig = serializationConfig.withSerializationInclusion(JsonSerialize.Inclusion.NON_NULL); AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(); mapper.setSerializationConfig(serializationConfig); mapper.setAnnotationIntrospector(introspector); try { return mapper.writeValueAsString(object); } catch (IOException e) { log.warn("Can't marshal search criteria."); throw new RuntimeException("Failed inFolder build criteria json.", e); } }
public static void main(String[] args) throws JsonMappingException { ObjectMapper jsonMapper = new ObjectMapper(); AnnotationIntrospector introspector = new AnnotationIntrospector.Pair(new JaxbAnnotationIntrospector(), new JacksonAnnotationIntrospector()); jsonMapper.setAnnotationIntrospector(introspector); JsonSchema schema = jsonMapper.generateJsonSchema(Testi.class); if(Testi.class.getAnnotation(XmlRootElement.class)!=null && !Testi.class.getAnnotation(XmlRootElement.class).name().equals("##default")) schema.getSchemaNode().put("name", Testi.class.getAnnotation(XmlRootElement.class).name()); else if(Testi.class.getAnnotation(XmlType.class)!=null && !Testi.class.getAnnotation(XmlType.class).name().equals("##default")) schema.getSchemaNode().put("name", Testi.class.getAnnotation(XmlType.class).name()); else schema.getSchemaNode().put("name", Testi.class.getSimpleName()); String schemaJson = schema.toString(); System.out.println(schemaJson); }
@Bean(name="defaultObjectMapper") public ObjectMapper getObjectMapper() { if(defaultObjectMapper==null) { ObjectMapper mapper = new ObjectMapper(); AnnotationIntrospector primary = new JaxbAnnotationIntrospector(); AnnotationIntrospector secondary = new JacksonAnnotationIntrospector(); AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary); mapper.getDeserializationConfig().setAnnotationIntrospector(pair); mapper.getDeserializationConfig().set(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.getSerializationConfig().setAnnotationIntrospector(pair); mapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL); mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false); mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true); this.defaultObjectMapper = mapper; } return defaultObjectMapper; }
private ObjectMapper createObjectMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector()); mapper.setSerializationInclusion(Inclusion.NON_NULL); mapper.configure(Feature.CLOSE_CLOSEABLE, false); return mapper; }
@Override protected <T> T createRESTClientProxy(String apiUrl, Class<T> proxy) { URI i = null; try { i = new URI(apiUrl); } catch (URISyntaxException ex) { throw new RuntimeException(ex); } ResteasyClientBuilder builder = new ResteasyClientBuilder(); builder.connectionCheckoutTimeout(CONNECTION_SETUP_TO, TimeUnit.SECONDS); builder.socketTimeout(CONNECTION_SETUP_TO, TimeUnit.SECONDS); builder.httpEngine(new URLConnectionEngine()); ResteasyProviderFactory.getInstance().register(builder); ResteasyClient client = builder.build(); client.register(new ClientRequestFilter() { @Override public void filter(ClientRequestContext requestContext) throws IOException { requestContext.getHeaders().add("User-Agent", getImplementationName() + "=" + getVersion()); } }); ObjectMapper mapper = new ObjectMapper(); JacksonJaxbJsonProvider jaxbProvider = new JacksonJaxbJsonProvider(mapper, JacksonJaxbJsonProvider.DEFAULT_ANNOTATIONS); mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector()); mapper.configure(Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); builder.register(jaxbProvider); builder.register(proxy); ResteasyWebTarget resteasyWebTarget = client.target(i); return resteasyWebTarget.proxy(proxy); }
public CustomJsonProvider(){ ObjectMapper mapper = new ObjectMapper(); mapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true); mapper.configure(org.codehaus.jackson.map.SerializationConfig.Feature.WRAP_ROOT_VALUE, true); _mapperConfig.setMapper(mapper); _mapperConfig.getConfiguredMapper().setAnnotationIntrospector(new JaxbAnnotationIntrospector()); }
public CustomJsonProviderList(){ ObjectMapper mapper = new ObjectMapper(); mapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true); mapper.configure(org.codehaus.jackson.map.SerializationConfig.Feature.WRAP_ROOT_VALUE, false); _mapperConfig.setMapper(mapper); _mapperConfig.getConfiguredMapper().setAnnotationIntrospector(new JaxbAnnotationIntrospector()); }
public CustomJsonProviderList(){ ObjectMapper mapper = new ObjectMapper(); mapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true); // Can not deserialize instance of ArrayList out of String mapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY,true); //Remove extra root value for class that include only a list mapper.configure(org.codehaus.jackson.map.SerializationConfig.Feature.WRAP_ROOT_VALUE, false); _mapperConfig.setMapper(mapper); _mapperConfig.getConfiguredMapper().setAnnotationIntrospector(new JaxbAnnotationIntrospector()); }
public JsonModelDeserializer(Class<T> deserializedObjectType) { super(); this.deserializedObjectType = deserializedObjectType; objectMapper = new ObjectMapper(); AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(); // make serializer use JAXB annotations (only) objectMapper.setDeserializationConfig(objectMapper.getDeserializationConfig().withAnnotationIntrospector(introspector)); objectTypeXmlTagName = deserializedObjectType.getAnnotation(XmlRootElement.class).name(); }
/** * Update the generator with a default codec and pretty printer * * @param jsonFactory Factory to set as codec * @param jsonGenerator Generator to configure */ private static void updateGenerator(JsonFactory jsonFactory, JsonGenerator jsonGenerator) { ObjectMapper mapper = new ObjectMapper(jsonFactory); //Update the annotation interceptor to also include jaxb annotations as a second choice AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); AnnotationIntrospector secondary = new JaxbAnnotationIntrospector() { /** * BUG FIX: * By contract, if findSerializationInclusion didn't encounter any annotations that should change the * inclusion value, it should return the default value it has received; but actually returns null, which * overrides the NON_NULL option we set. * The doc states issue JACKSON-256 which was supposed to be fixed in 1.5.0. *twilight zone theme song* */ @Override public JsonSerialize.Inclusion findSerializationInclusion(Annotated a, JsonSerialize.Inclusion defValue) { JsonSerialize.Inclusion inclusion = super.findSerializationInclusion(a, defValue); if (inclusion == null) { return defValue; } return inclusion; } }; AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary); mapper.getSerializationConfig().setAnnotationIntrospector(pair); mapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL); jsonGenerator.setCodec(mapper); jsonGenerator.useDefaultPrettyPrinter(); }
/** * Update the parser with a default codec * * @param jsonFactory Factory to set as codec * @param jsonParser Parser to configure */ private static void updateParser(JsonFactory jsonFactory, JsonParser jsonParser) { AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(); AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary); ObjectMapper mapper = new ObjectMapper(jsonFactory); mapper.getSerializationConfig().setAnnotationIntrospector(pair); mapper.getDeserializationConfig().setAnnotationIntrospector(pair); mapper.getDeserializationConfig().disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES); jsonParser.setCodec(mapper); }
public JsonProvider() { ObjectMapper mapper = getMapper(); //Update the annotation interceptor to also include jaxb annotations as a second choice AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(); AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary); mapper.getSerializationConfig().setAnnotationIntrospector(pair); mapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL); mapper.getDeserializationConfig().setAnnotationIntrospector(pair); //Ignore missing properties mapper.getDeserializationConfig().disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES); }
private ObjectMapper createObjectMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector()); mapper.setSerializationInclusion(Inclusion.NON_NULL); mapper.configure(Feature.CLOSE_CLOSEABLE, false); mapper.configure(Feature.FLUSH_AFTER_WRITE_VALUE, false); return mapper; }
static ObjectMapper createObjectMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector()); mapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL); mapper.configure(SerializationConfig.Feature.CLOSE_CLOSEABLE, false); return mapper; }
public JacksonJaxbContextResolver() { this.objectMapper = new ObjectMapper(); final AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); final AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(); final AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary); this.objectMapper.getDeserializationConfig().setAnnotationIntrospector(pair); this.objectMapper.getSerializationConfig().setAnnotationIntrospector(pair); }
public ObjectMapperFactoryBean() { this.objectMapper = new ObjectMapper(); this.objectMapper.setSerializationInclusion(Inclusion.NON_NULL); this.objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(); AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary); this.objectMapper.setAnnotationIntrospector(pair); }
@Override public ObjectMapper locateMapper(Class<?> type, MediaType mediaType) { ObjectMapper mapper = super.locateMapper(type, mediaType); AnnotationIntrospector introspector = new AnnotationIntrospector.Pair( new JaxbAnnotationIntrospector(), new JacksonAnnotationIntrospector() ); mapper.setAnnotationIntrospector(introspector); //mapper.setSerializationInclusion(Inclusion.NON_NULL); return mapper; }
/** * Creates json mapper. * * @return json mapper */ public static ObjectMapper createJsonMapper() { final AnnotationIntrospector jaxb = new JaxbAnnotationIntrospector(); final AnnotationIntrospector jackson = new JacksonAnnotationIntrospector(); final AnnotationIntrospector pair = new AnnotationIntrospector.Pair(jackson, jaxb); final ObjectMapper mapper = new ObjectMapper(); mapper.getDeserializationConfig().withAnnotationIntrospector(pair); mapper.getSerializationConfig().withAnnotationIntrospector(pair); return mapper; }
public static ObjectMapper createJsonMapper() { final AnnotationIntrospector jaxb = new JaxbAnnotationIntrospector(); final AnnotationIntrospector jackson = new JacksonAnnotationIntrospector(); final AnnotationIntrospector pair = new AnnotationIntrospector.Pair(jackson, jaxb); final ObjectMapper mapper = new ObjectMapper(); mapper.getDeserializationConfig().withAnnotationIntrospector(pair); mapper.getSerializationConfig().withAnnotationIntrospector(pair); return mapper; }
@Override public ObjectMapper locateMapper(Class<?> type, MediaType mediaType) { ObjectMapper mapper = super.locateMapper(type, mediaType); AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(); mapper.setAnnotationIntrospector(introspector); mapper.getSerializationConfig() .setSerializationInclusion(Inclusion.NON_NULL); return mapper; }
public CustomJSONProvider() { super(); ObjectMapper mapper = new ObjectMapper(); mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector()); mapper.configure(org.codehaus.jackson.map.SerializationConfig.Feature.WRAP_ROOT_VALUE, true); mapper.setSerializationInclusion(Inclusion.NON_NULL); mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); mapper.configure(org.codehaus.jackson.map.SerializationConfig.Feature.INDENT_OUTPUT, true); mapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true); mapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); super.setMapper(mapper); }
private static String serialize(Object quantumModel, boolean rootObject) throws JsonGenerationException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(); mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector()); mapper.configure(org.codehaus.jackson.map.SerializationConfig.Feature.WRAP_ROOT_VALUE, !rootObject); mapper.setSerializationInclusion(Inclusion.NON_NULL); mapper.configure(org.codehaus.jackson.map.SerializationConfig.Feature.INDENT_OUTPUT, true); return mapper.writeValueAsString(quantumModel); }
private static Object deserialize(Class<?> quantumObjectClass, String serializedObject, boolean rootObject) throws JsonParseException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(); mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector()); mapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, !rootObject); mapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); return mapper.readValue(serializedObject, quantumObjectClass); }
public static void configObjectMapper(ObjectMapper mapper) { AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(); mapper.setAnnotationIntrospector(introspector); mapper.setSerializationInclusion(Inclusion.NON_NULL); }
public static void configObjectMapper(ObjectMapper mapper) { AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(); mapper.setAnnotationIntrospector(introspector); mapper.getSerializationConfig(). setSerializationInclusion(Inclusion.NON_NULL); }
public JacksonProvider() { AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(); AnnotationIntrospector secondary = new JacksonAnnotationIntrospector(); mapper.setAnnotationIntrospector(new AnnotationIntrospector.Pair(introspector, secondary)); mapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false); }
@Override protected void serviceStart() throws Exception { super.serviceStart(); LOG.info("Starting {}", getName()); summaryStore.start(); Configuration conf = getConfig(); aclManager = new TimelineACLsManager(conf); aclManager.setTimelineStore(summaryStore); summaryTdm = new TimelineDataManager(summaryStore, aclManager); summaryTdm.init(conf); addService(summaryTdm); // start child services that aren't already started super.serviceStart(); if (!fs.exists(activeRootPath)) { fs.mkdirs(activeRootPath); fs.setPermission(activeRootPath, ACTIVE_DIR_PERMISSION); } if (!fs.exists(doneRootPath)) { fs.mkdirs(doneRootPath); fs.setPermission(doneRootPath, DONE_DIR_PERMISSION); } objMapper = new ObjectMapper(); objMapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector()); jsonFactory = new MappingJsonFactory(objMapper); final long scanIntervalSecs = conf.getLong( YarnConfiguration .TIMELINE_SERVICE_ENTITYGROUP_FS_STORE_SCAN_INTERVAL_SECONDS, YarnConfiguration .TIMELINE_SERVICE_ENTITYGROUP_FS_STORE_SCAN_INTERVAL_SECONDS_DEFAULT ); final long cleanerIntervalSecs = conf.getLong( YarnConfiguration .TIMELINE_SERVICE_ENTITYGROUP_FS_STORE_CLEANER_INTERVAL_SECONDS, YarnConfiguration .TIMELINE_SERVICE_ENTITYGROUP_FS_STORE_CLEANER_INTERVAL_SECONDS_DEFAULT ); final int numThreads = conf.getInt( YarnConfiguration.TIMELINE_SERVICE_ENTITYGROUP_FS_STORE_THREADS, YarnConfiguration .TIMELINE_SERVICE_ENTITYGROUP_FS_STORE_THREADS_DEFAULT); LOG.info("Scanning active directory {} every {} seconds", activeRootPath, scanIntervalSecs); LOG.info("Cleaning logs every {} seconds", cleanerIntervalSecs); executor = new ScheduledThreadPoolExecutor(numThreads, new ThreadFactoryBuilder().setNameFormat("EntityLogPluginWorker #%d") .build()); executor.scheduleAtFixedRate(new EntityLogScanner(), 0, scanIntervalSecs, TimeUnit.SECONDS); executor.scheduleAtFixedRate(new EntityLogCleaner(), cleanerIntervalSecs, cleanerIntervalSecs, TimeUnit.SECONDS); }
public CustomJsonProvider(){ ObjectMapper mapper = new ObjectMapper(); mapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true); mapper.configure(org.codehaus.jackson.map.SerializationConfig.Feature.WRAP_ROOT_VALUE, true); // Can not deserialize instance of ArrayList out of String mapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY,true); _mapperConfig.setMapper(mapper); _mapperConfig.getConfiguredMapper().setAnnotationIntrospector(new JaxbAnnotationIntrospector()); }
private static Pair createJaxbJacksonAnnotationIntrospector() { AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(); AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector(); return new AnnotationIntrospector.Pair(jacksonIntrospector, jaxbIntrospector); }