yasson
yasson copied to clipboard
Can Yasson support something like the @JsonIgnoreProperties of Jackson?
I encountered an issue in Groovy - https://github.com/hei1233212000/yasson-groovy-not-working where Yasson is trying to invoke some getter which has method arguments needed. e.g: MetaClass.getAttribute(Class sender, Object receiver, String messageName, boolean useSuper)
I don't see problems doing it. @bravehorsie, any concerns?
We do have @JsonbTransient to supply similar functionality.
There are no problems adding it, but the annotation itself should be added to jsonb spec project.
Hi @bravehorsie, I see a little bit different between the @JsonIgnoreProperties and the @JsonbTransient
You can NOT mark the field or property as transient by @JsonbTransient when you could not modify the source code. (e.g: I extend the Class from from other projects or using the POGO, my example)
And I think it would be great to put it in the JSON-B spec but I hope Yasson could support it earlier than the spec is confirmed to be modified.
@hei1233212000 sure, I didn't mean they are identical.
If you can't modify the code, how would you apply @JsonbIgnoreProperties? It's meant to be used class level right?
@bravehorsie yes, use the @jsonbignoreproperties in class level
I know I'm super late to this issue, but @hei1233212000 I believe the immediate issue you were facing was resolved a while back by PR #66.
Aside from the specific scenario, I agree that a general annotation may be useful at the class level.
For example if we have:
// Don't have access to this source
public class ThirdPartyClass {
public String junk1;
public String junk2;
public String important;
}
We could use a class level annotation as discussed above to blacklist certain properties, such as:
@JsonbIgnoreProperties({"junk1", "junk2"})
public class MyClass extends ThirdPartyClass {}
However, I think it would be more useful to white-list properties rather than black-list them, for example:
@JsonbProperties({"important"})
public class MyClass extends ThirdPartyClass {}
@bravehorsie any thoughts on either of the above approaches?
Thank you @aguibert !
Besides, I think white list and black list would be useful in different scenarios. For an example, the class has many fields but you only want to ignore one or two fields. :)
TBH, this sounds pretty much like a mix-in from Jackson: https://github.com/FasterXML/jackson-docs/wiki/JacksonMixInAnnotations
The advantage of jackson: Mix-Ins can also be applied to final classes (which would not work in your case).
For a quick solution:
@JsonbTransient
public groovy.lang.MetaClass metaClass;
I think the current proper way is to create a custom serializer. @JsonbIgnoreProperties in the spec can be much nicer.