Код: Выделить всё
@Bean(name = "gcpObjectMapper")
public ObjectMapper gcpMenuSyncMessageObjectMapper(Jackson2ObjectMapperBuilder builder) {
final ObjectMapper objectMapper = builder
.createXmlMapper(false)
.build();
// Some other custom configuration for supporting Java 8 features
objectMapper.registerModule(new JavaTimeModule());
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.setDefaultTyping(new StdTypeResolverBuilder()
.init(JsonTypeInfo.Id.NONE, null)
.inclusion(JsonTypeInfo.As.EXISTING_PROPERTY)
.typeProperty(null)
.typeIdVisibility(false));
return objectMapper;
}
Код: Выделить всё
private ByteString convertPayload(@NotNull Foo payload) throws BusinessRuntimeException {
try {
String jsonString = objectMapper.writeValueAsString(payload);
return ByteString.copyFromUtf8(jsonString);
} catch (JsonProcessingException e) {
log.error("Error converting payload to JSON", e);
throw new BusinessRuntimeException(e);
}
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... jectmapper
Мобильная версия