List of usage examples for com.fasterxml.jackson.databind.module SimpleModule addDeserializer
public <T> SimpleModule addDeserializer(Class<T> type, JsonDeserializer<? extends T> deser)
From source file:org.dd4t.databind.builder.json.JsonDataBinder.java
protected void configureMapper() { // This is the hook where view models are custom generated final ComponentPresentationDeserializer componentPresentationDeserializer = new ComponentPresentationDeserializer( this.concreteComponentPresentationImpl, this.concreteComponentTemplateImpl, this.concreteComponentImpl); final SimpleModule module = new SimpleModule("ComponentPresentationDeserializerModule", new Version(1, 0, 0, "RELEASE", "org.dd4t", "dd4t-databind")); module.addDeserializer(ComponentPresentation.class, componentPresentationDeserializer); GENERIC_MAPPER.registerModule(module); GENERIC_MAPPER.addMixInAnnotations(Field.class, BaseFieldMixIn.class); LOG.debug("Mapper configured for: {} and {}", this.concreteComponentPresentationImpl.toString(), this.concreteComponentTemplateImpl.toString()); }
From source file:edu.psu.swe.scim.server.utility.AttributeUtil.java
@PostConstruct public void init() { // TODO move this to a CDI producer objectMapper = new ObjectMapper(); JaxbAnnotationModule jaxbAnnotationModule = new JaxbAnnotationModule(); objectMapper.registerModule(jaxbAnnotationModule); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(objectMapper.getTypeFactory()); AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector(); AnnotationIntrospector pair = new AnnotationIntrospectorPair(jacksonIntrospector, jaxbIntrospector); objectMapper.setAnnotationIntrospector(pair); objectMapper.setSerializationInclusion(Include.NON_NULL); SimpleModule module = new SimpleModule(); module.addDeserializer(ScimResource.class, new ScimResourceDeserializer(this.registry, this.objectMapper)); objectMapper.registerModule(module); }
From source file:com.corundumstudio.socketio.protocol.JacksonJsonSupport.java
protected void init(ObjectMapper objectMapper) { SimpleModule module = new SimpleModule(); module.setSerializerModifier(modifier); module.addDeserializer(Event.class, eventDeserializer); module.addDeserializer(AckArgs.class, ackArgsDeserializer); objectMapper.registerModule(module); objectMapper.setSerializationInclusion(Include.NON_NULL); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.configure(SerializationFeature.WRITE_BIGDECIMAL_AS_PLAIN, true); objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); }
From source file:com.amazonaws.services.dynamodbv2.streamsadapter.model.RecordObjectMapper.java
public RecordObjectMapper() { super();/*from w ww . j a v a 2s . c o m*/ SimpleModule module = new SimpleModule(MODULE, Version.unknownVersion()); // Deal with (de)serializing of byte[]. module.addSerializer(ByteBuffer.class, new ByteBufferSerializer()); module.addDeserializer(ByteBuffer.class, new ByteBufferDeserializer()); // Deal with (de)serializing of Date module.addSerializer(Date.class, DateSerializer.instance); module.addDeserializer(Date.class, new DateDeserializer()); // Don't serialize things that are null this.setSerializationInclusion(JsonInclude.Include.NON_NULL); this.addMixInAnnotations(AttributeValue.class, AttributeValueMixIn.class); this.addMixInAnnotations(Record.class, RecordMixIn.class); this.addMixInAnnotations(StreamRecord.class, StreamRecordMixIn.class); }
From source file:io.swagger.test.examples.ExampleBuilderTest.java
@Test public void testComplexArrayWithExample() throws Exception { Map<String, Model> definitions = new HashMap<String, Model>(); Model address = new ModelImpl().example("{\"foo\":\"bar\"}").xml(new Xml().name("address")) .property("street", new StringProperty().example("12345 El Monte Blvd")) .property("city", new StringProperty().example("Los Altos Hills")) .property("state", new StringProperty().example("CA").minLength(2).maxLength(2)) .property("zip", new StringProperty().example("94022")); definitions.put("Address", address); // register the JSON serializer SimpleModule simpleModule = new SimpleModule(); simpleModule.addSerializer(new JsonNodeExampleSerializer()); simpleModule.addDeserializer(Example.class, new JsonExampleDeserializer()); Json.mapper().registerModule(simpleModule); Example rep = (Example) ExampleBuilder.fromProperty(new StringProperty("hello").example("fun"), definitions);//w w w .ja v a 2 s . co m assertEqualsIgnoreLineEnding(Json.pretty(rep), "\"fun\""); }
From source file:es.logongas.ix3.web.json.impl.JsonReaderImplEntityJackson.java
public JsonReaderImplEntityJackson(Class clazz) { this.clazz = clazz; objectMapper = new ObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true); SimpleModule module = new SimpleModule(); module.addDeserializer(java.util.Date.class, new DateDeserializer()); objectMapper.registerModule(module); }
From source file:org.apache.unomi.persistence.spi.CustomObjectMapper.java
public CustomObjectMapper() { super();/*from ww w . j a va2 s . c om*/ super.registerModule(new JaxbAnnotationModule()); configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); ISO8601DateFormat dateFormat = new ISO8601DateFormat(); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); setDateFormat(dateFormat); SimpleModule deserializerModule = new SimpleModule("PropertyTypedObjectDeserializerModule", new Version(1, 0, 0, null, "org.apache.unomi.rest", "deserializer")); PropertyTypedObjectDeserializer propertyTypedObjectDeserializer = new PropertyTypedObjectDeserializer(); propertyTypedObjectDeserializer.registerMapping("type=.*Condition", Condition.class); deserializerModule.addDeserializer(Object.class, propertyTypedObjectDeserializer); ItemDeserializer itemDeserializer = new ItemDeserializer(); deserializerModule.addDeserializer(Item.class, itemDeserializer); Map<String, Class<? extends Item>> classes = new HashMap<>(); classes.put(Campaign.ITEM_TYPE, Campaign.class); classes.put(CampaignEvent.ITEM_TYPE, CampaignEvent.class); classes.put(Event.ITEM_TYPE, Event.class); classes.put(Goal.ITEM_TYPE, Goal.class); classes.put(Persona.ITEM_TYPE, Persona.class); classes.put(Rule.ITEM_TYPE, Rule.class); classes.put(Scoring.ITEM_TYPE, Scoring.class); classes.put(Segment.ITEM_TYPE, Segment.class); classes.put(Session.ITEM_TYPE, Session.class); classes.put(ConditionType.ITEM_TYPE, ConditionType.class); classes.put(ActionType.ITEM_TYPE, ActionType.class); for (Map.Entry<String, Class<? extends Item>> entry : classes.entrySet()) { propertyTypedObjectDeserializer.registerMapping("itemType=" + entry.getKey(), entry.getValue()); itemDeserializer.registerMapping(entry.getKey(), entry.getValue()); } propertyTypedObjectDeserializer.registerMapping("itemType=.*", CustomItem.class); super.registerModule(deserializerModule); }
From source file:com.zenesis.qx.remote.ProxyObjectMapper.java
/** * Constructor/*from w w w.j a v a 2s . c o m*/ * @param tracker * @param indent whether to indent JSON * @param rootDir root directory to serialise all File's as relative to */ public ProxyObjectMapper(ProxySessionTracker tracker, boolean indent, File rootDir) { super(); this.tracker = tracker; SimpleModule module = new SimpleModule("ProxyObjectMapper", Version.unknownVersion()); module.addSerializer(Proxied.class, new ProxiedSerializer()); module.addDeserializer(Proxied.class, new ProxiedDeserializer()); module.addSerializer(Date.class, new DateSerializer()); module.addSerializer(String.class, new StringSerializer()); module.addSerializer(Enum.class, new EnumSerializer()); module.addSerializer(File.class, new FileSerializer(rootDir)); module.addDeserializer(File.class, new FileDeserializer(rootDir)); module.addSerializer(Map.class, new MapSerializer()); registerModule(module); }
From source file:uk.ac.cam.cl.dtg.segue.dao.content.ContentMapper.java
/** * Creates a brand new object mapper./*w ww . ja v a2s. co m*/ * This should be used sparingly as it is resource intensive to maintain these things. * * @return ObjectMapper that has been configured to handle the segue recursive object model. */ public ObjectMapper generateNewPreconfiguredContentMapper() { ContentBaseDeserializer contentDeserializer = new ContentBaseDeserializer(); contentDeserializer.registerTypeMap(jsonTypes); ChoiceDeserializer choiceDeserializer = new ChoiceDeserializer(contentDeserializer); QuestionValidationResponseDeserializer validationResponseDeserializer = new QuestionValidationResponseDeserializer( contentDeserializer, choiceDeserializer); SimpleModule contentDeserializerModule = new SimpleModule("ContentDeserializerModule"); contentDeserializerModule.addDeserializer(ContentBase.class, contentDeserializer); contentDeserializerModule.addDeserializer(Choice.class, choiceDeserializer); contentDeserializerModule.addDeserializer(QuestionValidationResponse.class, validationResponseDeserializer); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(contentDeserializerModule); return objectMapper; }
From source file:org.zalando.problem.ProblemModule.java
@Override public void setupModule(final SetupContext context) { final SimpleModule module = new SimpleModule(); module.setMixInAnnotation(Exceptional.class, stacktraces ? ExceptionalWithStacktraceMixin.class : ExceptionalMixin.class); module.setMixInAnnotation(DefaultProblem.class, DefaultProblemMixIn.class); module.setMixInAnnotation(Problem.class, ProblemMixIn.class); module.addSerializer(StatusType.class, new StatusTypeSerializer()); module.addDeserializer(StatusType.class, new StatusTypeDeserializer(statuses)); module.setupModule(context);//from ww w . j a v a2 s. com }