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); }
/** * Creates a new {@link MetricsServlet} with a {@link Properties} and {@link MetricRegistry}. * * @param registry the metric registry to register */ public MetricsServlet(MetricRegistry registry) { mMetricsRegistry = registry; mObjectMapper = new ObjectMapper().registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.MILLISECONDS, false)); }
private static ObjectMapper getMapper() { if (mapper == null) { mapper = new ObjectMapper(); SimpleModule module = new SimpleModule(); module.addDeserializer(RowMap.class, new RowMapDeserializer()); mapper.registerModule(module); } return mapper; }
private ObjectMapper createObjectMapper(KeyFormatter keyFormatter, boolean compact, boolean wrapped) { ObjectMapper newMapper = new ObjectMapper(); SimpleModule jsonModule = new SimpleModule(); jsonModule.setSerializerModifier(EurekaJacksonJsonModifiers.createJsonSerializerModifier(keyFormatter, compact)); newMapper.registerModule(jsonModule); newMapper.setSerializationInclusion(Include.NON_NULL); newMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, wrapped); newMapper.configure(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED, false); newMapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, wrapped); newMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); newMapper.addMixIn(Applications.class, ApplicationsJsonMixIn.class); if (compact) { addMiniConfig(newMapper); } else { newMapper.addMixIn(InstanceInfo.class, InstanceInfoJsonMixIn.class); } return newMapper; }
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);
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);
protected ObjectMapper serializeDataTimeAsLong(ObjectMapper mapper) { return mapper.copy().registerModule(new SimpleModule().addSerializer(DateTime.class, new DateTimeSerializer())); }
private static ObjectMapper setupInjectablesInObjectMapper(ObjectMapper objectMapper) { final GuiceAnnotationIntrospector guiceIntrospector = new GuiceAnnotationIntrospector(); objectMapper.setAnnotationIntrospectors( new AnnotationIntrospectorPair( guiceIntrospector, objectMapper.getSerializationConfig().getAnnotationIntrospector() ), new AnnotationIntrospectorPair( guiceIntrospector, objectMapper.getDeserializationConfig().getAnnotationIntrospector() ) ); GuiceInjectableValues injectableValues = new GuiceInjectableValues( GuiceInjectors.makeStartupInjectorWithModules( ImmutableList.of( binder -> { binder.bind(AuthorizerMapper.class).toInstance(AuthTestUtils.TEST_AUTHORIZER_MAPPER); binder.bind(ChatHandlerProvider.class).toInstance(new NoopChatHandlerProvider()); binder.bind(RowIngestionMetersFactory.class).toInstance(rowIngestionMetersFactory); } ) ) ); objectMapper.setInjectableValues(injectableValues); objectMapper.registerModule( new SimpleModule().registerSubtypes(new NamedType(NumberedShardSpec.class, "NumberedShardSpec")) ); return objectMapper; }
objectMapper.registerModule(BeanUtils.instantiateClass(module)); SimpleModule module = new SimpleModule(); addSerializers(module); addDeserializers(module); objectMapper.registerModule(module);
@Override public void serialize(WithGraph object, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { // FIXME: there is probably a simple way to automatically wire this up that I can't find // right now ObjectMapper mapper = SerializerUtils.getMapper(); SimpleModule module = SerializerUtils.getSerializerModule(); module.addSerializer(new VertexSerializer()); mapper.registerModule(module); //configuring jgen to just use the mapper doesn't actually work jgen.writeRawValue(mapper.writeValueAsString(object.getObject())); }
private static ObjectMapper getMapper(String secret_key) { if (mapper == null) { mapper = new ObjectMapper(); SimpleModule module = new SimpleModule(); module.addDeserializer(RowMap.class, new RowMapDeserializer(secret_key)); mapper.registerModule(module); } return mapper; }
/** * Creates a new instance of {@link WebInterfaceAbstractMetricsServlet}. */ public WebInterfaceAbstractMetricsServlet() { mObjectMapper = new ObjectMapper().registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.MILLISECONDS, false)); }
SimpleModule module = new SimpleModule(); module.setDeserializerModifier(new BeanDeserializerModifier() ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(module); User user = mapper.readValue(new File("test.json"), User.class);
bean.value = 42L; ObjectMapper mapper = new ObjectMapper(); new SimpleModule("LongDeserializerModule", new Version(1, 0, 0, null)); module.addDeserializer(Long.class, new LongJsonDeserializer()); mapper = new ObjectMapper(); mapper.registerModule(module);
ObjectMapper mapper = new ObjectMapper(); SimpleModule module = new SimpleModule("custom", Version.unknownVersion()); module.addSerializer(Student.class, new MyCustomSerializer()); mapper.registerModule(module);
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); }
/** * Register {@link NullValueSerializer} in the given {@link ObjectMapper} with an optional * {@code classPropertyTypeName}. This method should be called by code that customizes * {@link GenericJackson2JsonRedisSerializer} by providing an external {@link ObjectMapper}. * * @param objectMapper the object mapper to customize. * @param classPropertyTypeName name of the type property. Defaults to {@code @class} if {@literal null}/empty. * @since 2.2 */ public static void registerNullValueSerializer(ObjectMapper objectMapper, @Nullable String classPropertyTypeName) { // simply setting {@code mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)} does not help here since we need // the type hint embedded for deserialization using the default typing feature. objectMapper.registerModule(new SimpleModule().addSerializer(new NullValueSerializer(classPropertyTypeName))); }
public static ObjectMapper setupInjectablesInObjectMapper(ObjectMapper objectMapper) objectMapper.registerModule( new SimpleModule("testModule").registerSubtypes(LocalLoadSpec.class) );
@Override public void serialize(WithGraph object, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { // FIXME: there is probably a simple way to automatically wire this up that I can't find // right now ObjectMapper mapper = SerializerUtils.getMapper(); SimpleModule module = SerializerUtils.getSerializerModule(); module.addSerializer(new EdgeSerializer(object.getGraph())); mapper.registerModule(module); //configuring jgen to just use the mapper doesn't actually work jgen.writeRawValue(mapper.writeValueAsString(object.getObject())); }
SimpleModule module = new SimpleModule(); module.addSerializer(new ResultSetSerializer()); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(module); [ . . . do the query . . . ] ResultSet resultset = statement.executeQuery(query); // Use the DataBind Api here ObjectNode objectNode = objectMapper.createObjectNode(); // put the resultset in a containing structure objectNode.putPOJO("results", resultset); // generate all objectMapper.writeValue(stringWriter, objectNode);