private static AnnotationIntrospector createJaxbJacksonAnnotationIntrospector() { final AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()); final AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector(); return AnnotationIntrospector.pair(jacksonIntrospector, jaxbIntrospector); } }
@Override protected AnnotationIntrospector _resolveIntrospectors(Annotations[] annotationsToUse) { // Let's ensure there are no dups there first, filter out nulls ArrayList<AnnotationIntrospector> intr = new ArrayList<AnnotationIntrospector>(); for (Annotations a : annotationsToUse) { if (a != null) { intr.add(_resolveIntrospector(a)); } } int count = intr.size(); if (count == 0) { return AnnotationIntrospector.nopInstance(); } AnnotationIntrospector curr = intr.get(0); for (int i = 1, len = intr.size(); i < len; ++i) { curr = AnnotationIntrospector.pair(curr, intr.get(i)); } return curr; }
@Override protected JsonEndpointConfig _configForWriting(final ObjectMapper mapper, final Annotation[] annotations, final Class<?> defaultView) { final AnnotationIntrospector customIntrospector = mapper.getSerializationConfig().getAnnotationIntrospector(); // Set the custom (user) introspector to be the primary one. final ObjectMapper filteringMapper = mapper.setAnnotationIntrospector(AnnotationIntrospector.pair(customIntrospector, new JacksonAnnotationIntrospector() { @Override public Object findFilterId(final Annotated a) { final Object filterId = super.findFilterId(a); if (filterId != null) { return filterId; } if (a instanceof AnnotatedMethod) { final Method method = ((AnnotatedMethod) a).getAnnotated(); // Interested only in getters - trying to obtain "field" name from them. if (ReflectionHelper.isGetter(method)) { return ReflectionHelper.getPropertyName(method); } } if (a instanceof AnnotatedField || a instanceof AnnotatedClass) { return a.getName(); } return null; } })); return super._configForWriting(filteringMapper, annotations, defaultView); }
@Override protected AnnotationIntrospector _resolveIntrospectors(Annotations[] annotationsToUse) { // Let's ensure there are no dups there first, filter out nulls ArrayList<AnnotationIntrospector> intr = new ArrayList<AnnotationIntrospector>(); for (Annotations a : annotationsToUse) { if (a != null) { intr.add(_resolveIntrospector(a)); } } int count = intr.size(); if (count == 0) { return AnnotationIntrospector.nopInstance(); } AnnotationIntrospector curr = intr.get(0); for (int i = 1, len = intr.size(); i < len; ++i) { curr = AnnotationIntrospector.pair(curr, intr.get(i)); } return curr; }
@Override protected JsonEndpointConfig _configForWriting(final ObjectMapper mapper, final Annotation[] annotations, final Class<?> defaultView) { final AnnotationIntrospector customIntrospector = mapper.getSerializationConfig().getAnnotationIntrospector(); // Set the custom (user) introspector to be the primary one. final ObjectMapper filteringMapper = mapper.setAnnotationIntrospector(AnnotationIntrospector.pair(customIntrospector, new JacksonAnnotationIntrospector() { @Override public Object findFilterId(final Annotated a) { final Object filterId = super.findFilterId(a); if (filterId != null) { return filterId; } if (a instanceof AnnotatedMethod) { final Method method = ((AnnotatedMethod) a).getAnnotated(); // Interested only in getters - trying to obtain "field" name from them. if (ReflectionHelper.isGetter(method)) { return ReflectionHelper.getPropertyName(method); } } if (a instanceof AnnotatedField || a instanceof AnnotatedClass) { return a.getName(); } return null; } })); return super._configForWriting(filteringMapper, annotations, defaultView); }
public static ObjectMapper createDefaultMapper() { final ObjectMapper result = new ObjectMapper(); result.configure(SerializationFeature.INDENT_OUTPUT, true); result.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); result.setSerializationInclusion(JsonInclude.Include.NON_NULL); result.setAnnotationIntrospector(AnnotationIntrospector.pair( new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()), new JacksonAnnotationIntrospector() )); return result; } }
public JacksonContextResolver() { mapper = new ObjectMapper(); mapper.enable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME); mapper.setAnnotationIntrospector(AnnotationIntrospector.pair(new JacksonAnnotationIntrospector(), new JaxbAnnotationIntrospector(mapper.getTypeFactory()))); mapper.setSerializationInclusion(Include.NON_NULL); }
@VisibleForTesting static ObjectMapper createConjureParserObjectMapper() { ObjectMapper mapper = new ObjectMapper(new YAMLFactory()) .registerModule(new Jdk8Module()) .setAnnotationIntrospector( AnnotationIntrospector.pair( new KebabCaseEnforcingAnnotationInspector(), // needs to come first. new JacksonAnnotationIntrospector())); mapper.enable(JsonParser.Feature.STRICT_DUPLICATE_DETECTION); return mapper; } }
@Override protected AnnotationIntrospector _resolveIntrospectors(Annotations[] annotationsToUse) { // Let's ensure there are no dups there first, filter out nulls ArrayList<AnnotationIntrospector> intr = new ArrayList<AnnotationIntrospector>(); for (Annotations a : annotationsToUse) { if (a != null) { intr.add(_resolveIntrospector(a)); } } int count = intr.size(); if (count == 0) { return AnnotationIntrospector.nopInstance(); } AnnotationIntrospector curr = intr.get(0); for (int i = 1, len = intr.size(); i < len; ++i) { curr = AnnotationIntrospector.pair(curr, intr.get(i)); } return curr; }
@Override protected AnnotationIntrospector _resolveIntrospectors(Annotations[] annotationsToUse) { // Let's ensure there are no dups there first, filter out nulls ArrayList<AnnotationIntrospector> intr = new ArrayList<AnnotationIntrospector>(); for (Annotations a : annotationsToUse) { if (a != null) { intr.add(_resolveIntrospector(a)); } } int count = intr.size(); if (count == 0) { return AnnotationIntrospector.nopInstance(); } AnnotationIntrospector curr = intr.get(0); for (int i = 1, len = intr.size(); i < len; ++i) { curr = AnnotationIntrospector.pair(curr, intr.get(i)); } return curr; }
@Override protected AnnotationIntrospector _resolveIntrospectors(Annotations[] annotationsToUse) { // Let's ensure there are no dups there first, filter out nulls ArrayList<AnnotationIntrospector> intr = new ArrayList<AnnotationIntrospector>(); for (Annotations a : annotationsToUse) { if (a != null) { intr.add(_resolveIntrospector(a)); } } int count = intr.size(); if (count == 0) { return AnnotationIntrospector.nopInstance(); } AnnotationIntrospector curr = intr.get(0); for (int i = 1, len = intr.size(); i < len; ++i) { curr = AnnotationIntrospector.pair(curr, intr.get(i)); } return curr; }
@Override protected AnnotationIntrospector _resolveIntrospectors(Annotations[] annotationsToUse) { // Let's ensure there are no dups there first, filter out nulls ArrayList<AnnotationIntrospector> intr = new ArrayList<AnnotationIntrospector>(); for (Annotations a : annotationsToUse) { if (a != null) { intr.add(_resolveIntrospector(a)); } } int count = intr.size(); if (count == 0) { return AnnotationIntrospector.nopInstance(); } AnnotationIntrospector curr = intr.get(0); for (int i = 1, len = intr.size(); i < len; ++i) { curr = AnnotationIntrospector.pair(curr, intr.get(i)); } return curr; }
/** * Constructs a {@code JacksonObjectMapperProvider} with a custom object mapper. */ public JacksonObjectMapperProvider() { objectMapper = new ObjectMapper(); objectMapper.setAnnotationIntrospector(AnnotationIntrospector.pair(new JacksonAnnotationIntrospector(), new JaxbAnnotationIntrospector())); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); }
/** *creates a new web socket server * *@param port the port of the server *@param handler the dialog handler of the backend * */ public ChatWebSocket(int port, DialogHandler handler) { super(new InetSocketAddress(port)); this.handler = handler; AnnotationIntrospector firstInspector = new JacksonAnnotationIntrospector(); AnnotationIntrospector secondInspector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()); AnnotationIntrospector inspectors = AnnotationIntrospector.pair(firstInspector, secondInspector); mapper = new ObjectMapper(); mapper.setAnnotationIntrospector(inspectors); }
public JacksonJaxbJsonProvider() { super(); objectMapper.setAnnotationIntrospector(AnnotationIntrospector.pair(new JaxbAnnotationIntrospector(objectMapper.getTypeFactory()), new JacksonAnnotationIntrospector())); }
public JacksonJsonJaxbProvider() { super(); objectMapper.setAnnotationIntrospector(AnnotationIntrospector.pair(new JacksonAnnotationIntrospector(), new JaxbAnnotationIntrospector( objectMapper.getTypeFactory()))); }
protected static ObjectMapper createJacksonMapper(boolean indent) { @SuppressWarnings("deprecation") AnnotationIntrospector spec = AnnotationIntrospector.pair(new JacksonAnnotationIntrospector(), new com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector()); ObjectMapper mapper = new ObjectMapper(); @SuppressWarnings("deprecation") SimpleModule testModule = new SimpleModule("MyModule", new com.fasterxml.jackson.core.Version(1, 0, 0, null)); testModule.addSerializer(new ResourceSerializer(mapper)); mapper.registerModule(testModule); mapper.setAnnotationIntrospector(spec); mapper.configure(SerializationFeature.INDENT_OUTPUT, indent); return mapper; }
public static ObjectMapper create() { ObjectMapper mapper = new ObjectMapper(); // Support for annotated constructors, as generated by Lombok and @Data DeserializationConfig config = mapper.getDeserializationConfig(); AnnotationIntrospector pair = AnnotationIntrospector.pair(config.getAnnotationIntrospector(), new ConstructorPropertiesAnnotationIntrospector()); // OK return mapper.setAnnotationIntrospector(pair); }
public ApiObjectMapper() { // Print the JSON with indentation (ie. pretty print) configure(SerializationFeature.INDENT_OUTPUT, true); // Allow JAX-B annotations. setAnnotationIntrospector(AnnotationIntrospector.pair(getSerializationConfig().getAnnotationIntrospector(), new JaxbAnnotationIntrospector())); // Make Jackson respect @XmlElementWrapper. enable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME); // Print all dates in ISO8601 format setDateFormat(makeISODateFormat()); }
public ApiObjectMapper() { // Print the JSON with indentation (ie. pretty print) configure(SerializationFeature.INDENT_OUTPUT, true); // Allow JAX-B annotations. setAnnotationIntrospector(AnnotationIntrospector.pair(getSerializationConfig().getAnnotationIntrospector(), new JaxbAnnotationIntrospector())); // Make Jackson respect @XmlElementWrapper. enable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME); // Print all dates in ISO8601 format setDateFormat(makeISODateFormat()); }