Serialization and log4j, any recommendations?

544 views
Skip to first unread message

Dimitris

unread,
Aug 30, 2013, 1:42:47 PM8/30/13
to jacks...@googlegroups.com
Hello there,
I have a Logger instance (log4j library) in a class:

private final static Logger logger = Logger.getLogger(Person.class.getName());

When I try to serialize an object of that class it gives me the following:

com.fasterxml.jackson.databind.JsonMappingException: 
No serializer found for class org.apache.log4j.helpers.NullEnumeration and no properties discovered to create BeanSerializer 
(to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ) 
(through reference chain: 
com.vmware.vscale.core.AppState["logger"]->org.apache.log4j.Logger["parent"] >org.apache.log4j.spi.RootLogger["allAppenders"])

Adding @JsonIgnore, ignores it and everything works. However, when using the deserialized object it doesn't log anymore...

So the question is, what is a good way to take care of a logger? I just need to have it logging after it's deserialized.

Thank you,
Dimitris

Tatu Saloranta

unread,
Aug 30, 2013, 4:08:47 PM8/30/13
to Dimitris, jacks...@googlegroups.com
You probably need a custom serializer, deserializer, which includes whatever information you consider necessary to retain. At least name, but also if there is some configuration.

This is not something standard Jackson databind can help a lot with (as it can not contain references to 3rd party libs). But if this is/was common enough need, there is always possibility of simple "jackson-datatype-log4j" module (or even "jackson-datatype-logging" that could support slf4j too?).
Such an extension module could add full and proper handling of logger instances.

Alternatively, perhaps you could just consider using static logger references, which is a common usage pattern with loggers.

-+ Tatu +-



--
You received this message because you are subscribed to the Google Groups "jackson-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-dev...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages