-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ObjectMapper configuration #75
Comments
Hi can you describe the use case where you need this? |
Use case: The application makes an outgoing rest call to an external service and receives a response. And in order to be able to successfully deserialize this field, it must be possible to configure it Another cases:
Include only non empty:
Disable failing on empty beans:
Example of content in CustomByteArraySerializer class: `public class CustomByteArraySerializer extends ByteArraySerializer { @OverRide |
There are 2 options based on CDI to allow you to do that easily:
|
What I think of as the most simple solution is that you use your existing ObjectMapper to convert your object to a JsonNode. @Path("/hello")
public class ExampleResource {
private Logger log = LoggerFactory.getLogger(ExampleResource.class);
private ObjectMapper mapper;
@Inject
public ExampleResource(ObjectMapper mapper) {
mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:sss")); // Just for simplify example
this.mapper = mapper;
}
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
// Mapping object to JsonNode using existing ObjectMapper resulting in same json as actual send/received.
final JsonNode jsonNode = mapper.valueToTree(new Testing());
log.info("Test", KeyValueStructuredArgument.kv("KEY", jsonNode));
return "Hello RESTEasy";
}
static class Testing {
private Date now = new Date();
public Date getNow() {
return now;
}
}
} Resulting in a log like this: |
gsmet: Thanks for your proposal SlyngDK: Thanks for your proposal, it worked perfect! |
Hi!
Thanks for the answer on my previous issue, it worked nicely.
I think the extension would be more reusable if it was possible to supply own configuration of: com.fasterxml.jackson.databind.ObjectMapper
In my case usage fails with the following:
If I could apply my own configuration, something like this would solve my case:
@ApplicationScoped public class LogObjectMapper { @Inject ObjectMapper mapper; public ObjectMapper createForLogging() { mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX")); } }
I think the same configuration would be nice for jsonb also.
The text was updated successfully, but these errors were encountered: