Skip to content
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

Add support for subset of jackson annotations #32

Closed
bkhall opened this issue Nov 28, 2015 · 11 comments
Closed

Add support for subset of jackson annotations #32

bkhall opened this issue Nov 28, 2015 · 11 comments
Milestone

Comments

@bkhall
Copy link

bkhall commented Nov 28, 2015

To allow JSON tag names to NOT match field names, setters, and getters.

Ex:
Where a JSON object contains a tag like this: "name": "John",

It would properly populate a field in a class like this:

@JsonProperty("name")
protected String mPrettyName;

public String getPrettyName() {
    return mPrettyName;
}

public void setPrettyName(String prettyName) {
    mPrettyName = prettyName;
}

Note that the field, setter ,and getter do NOT match the JSON tag name.

@cowtowncoder
Copy link
Member

I'll have to think about this. One of main goals for jackson-jr is to keep things very compact, and this is why no annotation support was added. At the same time, small high-value additions can be considered.

In this case, perhaps the first part would be to figure out an extension point for registering an object that could handle naming. Such an object could handle annotation-based renaming, but also possible alternate external naming strategy.

Another thing to consider from extensibility standpoint is the added dependency to jackson annotations. This could be a reason implement this as separate maven (sub-module), within same project. As such it could also be contained in jackson-jr-all uber-jar.

@bkhall
Copy link
Author

bkhall commented Nov 29, 2015

Agreed, smaller is better, especially when using on Android. But, there's already a dependency on the jackson-core library due to an Exception reference from your project. The jackson-annotations library is only 33kb. Even adding it to the uber-jar, it's still smaller than the main jackson databinder.

@cowtowncoder
Copy link
Member

@bkhall Yes, it is smaller, but unlike core, can not easily be shaded. Not so much wrt size of the result (which is small, agreed), but that it is one additional external dependency. Anyway, adding configuration mechanism as a separate sub-module is probably the way to go, shading it (but not annotations -- they need to be separate public, non-relocated types IMO) seems reasonable to me.

@gregschlom
Copy link

This seems especially useful to map property names with underscores to camel case

@cowtowncoder
Copy link
Member

I think this should be an extension piece of some sort, similar to jr-stree, which is separate jar (except for uber-jar case). But would need hooks in jr-objects to plug in.

@mikeholler
Copy link

I think this is also a must in cases where object keys have spaces in them. In that case, such objects could not be represented by POJOs without the @JsonProperty annotation.

@cowtowncoder
Copy link
Member

It has been a while but I am now considering doing something to handle this and related issues.
Approach would be to:

  1. Create extension point that would allow sort of equivalent operations as Jackson's Bean[De]SerializerModifier, which allows for
    • Removal of properties (similar to @JsonIgnore, @JsonIgnoreProperties)
    • Renaming of properties (@JsonProperty)
    • Specifying serialization ordering (@JsonPropertyOrder)
  2. Create new module that constructs pluggable object that can read useful subset of Jackson annotations for relevant cases.

I'll have to see how feasible this is, but if it is and I have time, this would go in version 2.10.

@mukhtar
Copy link

mukhtar commented May 27, 2019

I assume this didn't make it into 2.10?

@cowtowncoder
Copy link
Member

2.10 is not out yet. But it may be that I won't have time to do it properly... would really like to get it done if at all possible.

@cowtowncoder
Copy link
Member

Did not make it in 2.10, but hoping to add in 2.11. Basic plan the same wrt Bean[De]SerializerModifier equivalent.

@cowtowncoder cowtowncoder added 2.11 and removed 2.10 labels Dec 17, 2019
@cowtowncoder cowtowncoder added this to the 2.11.0 milestone Feb 14, 2020
@cowtowncoder cowtowncoder changed the title Add support for jackson annotations syntax Add support for subset of jackson annotations Feb 14, 2020
@cowtowncoder
Copy link
Member

Now implemented: see

https://github.com/FasterXML/jackson-jr/tree/master/jr-annotation-support

for more details on usage, supported annotations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants