/** * Takes a JSON string that came from the frontend form submission and deserializes it into its {@link DataWrapper} dto * representation so that it can be converted to an MVEL expression * @param json * @return */ public DataWrapper convertJsonToDataWrapper(String json) { ObjectMapper mapper = new ObjectMapper(); DataDTODeserializer dtoDeserializer = new DataDTODeserializer(); SimpleModule module = new SimpleModule("DataDTODeserializerModule", new Version(1, 0, 0, null)); module.addDeserializer(DataDTO.class, dtoDeserializer); mapper.registerModule(module); if (json == null || "[]".equals(json)) { return null; } try { return mapper.readValue(json, DataWrapper.class); } catch (IOException e) { throw new RuntimeException(e); } }
ObjectMapper mapper = new ObjectMapper(); SimpleModule simpleModule = new SimpleModule("SimpleModule", new Version(1,0,0,null)); // simpleModule.addSerializer(new ItemSerializer()); simpleModule.addSerializer(Item.class, new ItemSerializer()); mapper.registerModule(simpleModule);
@Override public List<? extends Module> getJacksonModules() { return ImmutableList.<Module>of( new SimpleModule("DruidLookupModule").registerSubtypes(MapLookupExtractorFactory.class), new SimpleModule().registerSubtypes( new NamedType(LookupDimensionSpec.class, "lookup"), new NamedType(RegisteredLookupExtractionFn.class, "registeredLookup") ) ); }
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); }
@SuppressWarnings("unchecked") static SimpleModule register(SimpleModule module) { module.addKeyDeserializer(DateTime.class, new DateTimeKeyDeserializer()); module.addDeserializer(DateTime.class, new DateTimeDeserializer()); module.addSerializer(DateTime.class, ToStringSerializer.instance); module.addDeserializer(Interval.class, new JodaStuff.IntervalDeserializer()); module.addSerializer(Interval.class, ToStringSerializer.instance); JsonDeserializer<?> periodDeserializer = new PeriodDeserializer(); module.addDeserializer(Period.class, (JsonDeserializer<Period>) periodDeserializer); module.addSerializer(Period.class, ToStringSerializer.instance); module.addDeserializer(Duration.class, new DurationDeserializer()); module.addSerializer(Duration.class, ToStringSerializer.instance); return module; }
@Test public void testJsonSerialization() throws Exception { TestingTypeManager typeManager = new TestingTypeManager(); ObjectMapper mapper = new ObjectMapperProvider().get() .registerModule(new SimpleModule().addDeserializer(Type.class, new TestingTypeDeserializer(typeManager))); AllOrNoneValueSet all = AllOrNoneValueSet.all(HYPER_LOG_LOG); assertEquals(all, mapper.readValue(mapper.writeValueAsString(all), AllOrNoneValueSet.class)); AllOrNoneValueSet none = AllOrNoneValueSet.none(HYPER_LOG_LOG); assertEquals(none, mapper.readValue(mapper.writeValueAsString(none), AllOrNoneValueSet.class)); } }
LongJsonDeserializer deserializer = new LongJsonDeserializer(); SimpleModule module = new SimpleModule("LongDeserializerModule", new Version(1, 0, 0, null)); module.addDeserializer(Long.class, deserializer); ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(module);
@Before public void before() { mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT); final SimpleModule module = new SimpleModule(HyperLogLogPlusJsonConstants.HYPER_LOG_LOG_PLUS_SERIALISER_MODULE_NAME, new Version(1, 0, 0, null)); module.addSerializer(HyperLogLogPlus.class, new HyperLogLogPlusJsonSerialiser()); module.addDeserializer(HyperLogLogPlus.class, new HyperLogLogPlusJsonDeserialiser()); mapper.registerModule(module); }
@Override public void configureObjectMapper(ObjectMapper mapper) { super.configureObjectMapper(mapper); final SimpleModule customDeserializer = new SimpleModule(TrueFxTicker.class.getSimpleName(), Version.unknownVersion()); customDeserializer.addDeserializer( TrueFxTicker.class, new TrueFxTicker.TrueFxTickerDeserializer()); mapper.registerModule(customDeserializer); } };
@Test public void testCanSerialiseWithCustomObjectMapper() throws IOException { //Bitmap of (2,3000,300000) serialised in 0.5.11 Roaring Bitmap base 64 encoded String serialisedComparisonBitmap = "{\"roaringBitmap\":{\"value\":\"OjAAAAIAAAAAAAEABAAAABgAAAAcAAAAAgC4C+CT\"}}"; RoaringBitmap comparisonBitmap = new RoaringBitmap(); comparisonBitmap.add(2); comparisonBitmap.add(3000); comparisonBitmap.add(300000); final ObjectMapper mapper = JSONSerialiser.createDefaultMapper(); final SimpleModule bitmapModule = new SimpleModule(RoaringBitmapConstants.BITMAP_MODULE_NAME, new Version(1, 0, 9, null, null, null)); bitmapModule.addSerializer(RoaringBitmap.class, new RoaringBitmapJsonSerialiser()); bitmapModule.addDeserializer(RoaringBitmap.class, new RoaringBitmapJsonDeserialiser()); mapper.registerModule(bitmapModule); RoaringBitmap testBitmap = mapper.readValue(serialisedComparisonBitmap, RoaringBitmap.class); assertEquals(comparisonBitmap, testBitmap); String serialisedBitmap = mapper.writeValueAsString(testBitmap); assertEquals(serialisedBitmap, serialisedComparisonBitmap); } }
SimpleModule module = new SimpleModule("ProductDeserializerModule", new Version(1, 0, 0, null)); module.addDeserializer(Product.class, new ProductJsonDeserializer()); mapper = new ObjectMapper(); mapper.registerModule(module);
ObjectMapper mapper = new ObjectMapper(); // add module for meta data permissions SimpleModule module = new SimpleModule("IncludeMetaData", new Version(0, 1, 0, "alpha")); module.addSerializer(MetaClass.class, new MetaDataSerializer(permissions, p instanceof AbstractBean ? ((AbstractBean) p).isOwner() : false)); mapper.registerModule(module); // ignore missing filters mapper.setFilters(new SimpleFilterProvider().setFailOnUnknownId(false)); return mapper.writerWithView(Views.Admin.class).writeValueAsString(p)
/** Create a module including the serializer and deserializer for local dates */ public static SimpleModule makeModule () { Version moduleVersion = new Version(1, 0, 0, null, null, null); SimpleModule module = new SimpleModule("LocalDate", moduleVersion); module.addSerializer(LocalDate.class, new JodaLocalDateSerializer()); module.addDeserializer(LocalDate.class, new JodaLocalDateDeserializer()); return module; }
public static void configureStockJoltObjectMapper( ObjectMapper objectMapper ) { // All Json maps should be deserialized into LinkedHashMaps. SimpleModule stockModule = new SimpleModule("stockJoltMapping", new Version(1, 0, 0, null, null, null)) .addAbstractTypeMapping( Map.class, LinkedHashMap.class ); objectMapper.registerModule(stockModule); // allow the mapper to parse JSON with comments in it objectMapper.configure( JsonParser.Feature.ALLOW_COMMENTS, true); }
@Inject public MongoJackObjectMapperProvider(ObjectMapper objectMapper) { // add the mongojack specific stuff on a copy of the original ObjectMapper to avoid changing the singleton instance this.objectMapper = objectMapper.copy() .addHandler(new ReplaceUnknownSubtypesWithFallbackHandler()) .setPropertyNamingStrategy(new PreserveLeadingUnderscoreStrategy()) .registerModule(new SimpleModule("JSR-310-MongoJack") .addSerializer(ZonedDateTime.class, new MongoZonedDateTimeSerializer()) .addDeserializer(ZonedDateTime.class, new MongoZonedDateTimeDeserializer()) .addSerializer(DateTime.class, new MongoJodaDateTimeSerializer()) .addDeserializer(DateTime.class, new MongoJodaDateTimeDeserializer())); MongoJackModule.configure(this.objectMapper); }
private void addDeserializers(ObjectMapper mapper) { SimpleModule module = new SimpleModule(); ObjectReader reader = mapper.reader(); module.addDeserializer(Payload.class, new PayloadDeserializer(reader)); module.addDeserializer(Header.class, new HeaderDeserializer(reader)); mapper.registerModule(module); }
protected ObjectMapper serializeDataTimeAsLong(ObjectMapper mapper) { return mapper.copy().registerModule(new SimpleModule().addSerializer(DateTime.class, new DateTimeSerializer())); }
@Override public void configureObjectMapper(ObjectMapper objectMapper) { super.configureObjectMapper(objectMapper); SimpleModule module = new SimpleModule(); module.addSerializer(BigDecimal.class, new ToStringSerializer()); objectMapper.registerModule(module); } });
@Override public List<? extends Module> getJacksonModules() { return Collections.singletonList( new SimpleModule("HllSketchModule").registerSubtypes( new NamedType(HllSketchMergeAggregatorFactory.class, MERGE_TYPE_NAME), new NamedType(HllSketchBuildAggregatorFactory.class, BUILD_TYPE_NAME), new NamedType(HllSketchMergeAggregatorFactory.class, TYPE_NAME), new NamedType(HllSketchToStringPostAggregator.class, TO_STRING_TYPE_NAME), new NamedType(HllSketchUnionPostAggregator.class, UNION_TYPE_NAME), new NamedType(HllSketchToEstimateWithBoundsPostAggregator.class, ESTIMATE_WITH_BOUNDS_TYPE_NAME) ).addSerializer(HllSketch.class, new HllSketchJsonSerializer()) ); }
public static SimpleModule getSerializerModule() { SimpleModule module = new SimpleModule("VertexJSONSerializer", new Version(1, 0, 0, null, "com.fasterxml.jackson.module", "jackson-module-jaxb-annotations")); module.addSerializer(new GeometrySerializer()); module.addSerializer(new CoordinateSerializer()); module.addSerializer(new PackedCoordinateSequenceSerializer()); return module; }