-
Notifications
You must be signed in to change notification settings - Fork 15
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
JSOG support without the need to annotate the classes #5
Comments
This is really a question for Tatu on the Jackson mailing list. FWIW, I'd like to know the answer myself. I'll ask and report back. |
Tatu says:
I'm turning this into a feature request to add an AnnotationIntrospector that enables this behavior. |
👍 , would love to see this implemented, or alternatively some direction on how I could do it myself |
Unfortunately my Jackson-fu is inadequate, but we'll keep this open until somebody figures it out. |
I didn't test it but you could create a "Mixin" class with the JsonIdentityInfo annotation. See: http://wiki.fasterxml.com/JacksonMixInAnnotations You can even set the mixin to be applied to all classes:
(BTW the ObjectMapper was meant to be created once and shared across the application) |
BTW, I did test and works as charm! Create a simple class as mixin:
Then create a
|
I'm having some difficulty round tripping using the SimpleModule approach... when I try
I get
Same result for
Class is like this:
This was with Jackson 2.5.1 and 2.7.0. I checked out the code from this project and wrote this in unit test form and got a different exception due to 2.5.0 dep in your pom:
|
Ah ha.. my simple case above succeeds if I remove
which I had previously added to handle abstract types (in more complicated code for actual use), so it seems that the workaround by @cjalmeida only stumbles if one is trying to use this technique to handle abstract types |
Please prioritize this. For some classes in 3rd party library, we cannot add annotations, we just need to serialize to JSON. Thanks |
@chaoyangnz what's wrong with using jackson mixins? That's the natural jackson solution to "I can't annotate my classes". |
I have a
I will isolate the issue and provide you the example shortly. |
found the cause. the mixin is applied to which made the conflicts. Do you know how i can set mixin in all classes except some classes? |
is it possible to make JSOG work without annotating the class hierarchy?
I have a class hierarchy which I do not control and need to serialize into JSON, unfortunately it has cyclic references. I understand it requires some book keeping (checking for each object if it was already referenced) , but sometimes it can be the only way to use JSOG.
The text was updated successfully, but these errors were encountered: