FrankChen021 commented on issue #12912:
URL: https://github.com/apache/druid/issues/12912#issuecomment-1221274141
Hi @BartMiki
My point is, since this is a special case caused by jackson, we need to try
hide these special treatment from users.
If we provide an extra API to serialize the object returned by `toMap()`
instead of using ObjectMapper directly, every caller has to know there's such
API provided, and they have to read some document to make sure they're using
the right way to serialize, and they also may dive into the detail of such API
to know why such API is provided.
That's a burden for users.
A better suggestion is using customer serializer mechanism provided by
jackson.
```java
public interface Event {
EventMap toMap();
...
}
@JsonSerialize(using = ACustomerMapSerializer.class)
class EventMap extends HashMap<String, Object> {
}
public class EventMapSerializer extends JsonSerializer<EventMap>
{
@Override
public void serialize(
EventMap value,
JsonGenerator jgen,
SerializerProvider provider) throws IOException
{
// do serialization
}
@Override
public Class<EventMap> handledType()
{
return EventMap.class;
}
}
```
By using such mechansim, user can serialize `ACustomerMap` directly by using
`ObjectMapper`.
And in the implementation of `ACustomerMapSerializer.serialize`, I think
there won't be two phase serialization as implemented in current PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]