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

Introduce config override for includeAsProperty #1566

Merged

Conversation

CarstenWickner
Copy link
Contributor

@CarstenWickner CarstenWickner commented Mar 19, 2017

Re-created pull request #1564 based on current master branch (version 2.9). Implements #1522

To avoid collisions with the existing (overloaded) getDefaultPropertyInclusion() methods, I added the new ones (with the additional Class<?> parameter) as getDefaultInclusion(), since they are explicitly looking up the JsonInclude.Value for a single property.

Please have another look, @cowtowncoder. The added unit tests should demonstrate why this second Class<?> parameter is required.

@cowtowncoder
Copy link
Member

Apologies for this taking long time: it's high on my todo list but fixing some urgent 2.8 issues (to get 2.8.8 out), and remaining 2.9 oddities has taken longer than expected. But I wanted to add a note here since I think this is a valuable addition I hope also makes it in 2.9 (which is not going to happen for all issues marker with 2.9)

{
JsonInclude.Value v0 = getConfigOverride(propertyType).getIncludeAsProperty();
if (v0 != null) {
return v0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May not be a big issue, but usually it'd make sense to merge with defaults;

JsonInclude.Value.merge(defaultIncl, v0);

method does handle null without problems (in case defaultIncl passed as null).

I think this mostly matters for things like global defaults for just one aspects (like don't include nulls for values); not sure if this is commonly used (probably isn't), but easy to add.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be inconsistent with the logic in getDefaultPropertyInclusion(Class, Value).
Should I add it anyway? And if yes, should this merging also cover the potential other override value?

JsonInclude.Value result = defaultIncl;
JsonInclude.Value v1 = getConfigOverride(baseType).getInclude();
if (v1 != null) {
    result = JsonInclude.Value.merge(result, v1);
)
JsonInclude.Value v0 = getConfigOverride(propertyType).getIncludeAsProperty();
if (v0 != null) {
    result = JsonInclude.Value.merge(result, v0);
)
return result;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think this is correct. I do not recall why merge wasn't done in the other case; may have been a simple oversight on my part.

*
* @since 2.9
*/
public abstract JsonInclude.Value getDefaultInclusion(Class<?> baseType,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to add brief explanation regarding difference between baseType, propertyType, in context of properties of given POJO.

@@ -41,6 +41,11 @@ public MutableConfigOverride setInclude(JsonInclude.Value v) {
return this;
}

public MutableConfigOverride setIncludeAsProperty(JsonInclude.Value v) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to add javadocs (even if other methods don't necessarily have them either :) ) for brief explanation.

// latter having precedence)
// Cc) per-property override
// config override having precedence)
// (c) per-property override (from annotation or config overrides;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is sort of correct but maybe misleading, as config override is for type-of-property, but not for specific property. Not sure how to properly explain the distinction.

* {@link JsonSerialize#include} annotation property work
* as expected.
*/
public class JsonIncludeOverrideTest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it would make sense to create a separate test class to contain new tests? Not sure which makes most sense: these are of course related, just trying to find good balance between huge test classes and big number of classes.

@cowtowncoder
Copy link
Member

Ok so I think this makes sense, and I hope to get this integrated for 2.9. Added some minor comments for consideration.

@CarstenWickner
Copy link
Contributor Author

Updated according to review comments. Let me know if I should move the tests around or fix-up something else.

@cowtowncoder
Copy link
Member

I think we'll call it good enough!

@cowtowncoder cowtowncoder merged commit d07acfc into FasterXML:master May 1, 2017
@CarstenWickner CarstenWickner deleted the cfg-override_include-as-prop branch May 2, 2017 13:17
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

Successfully merging this pull request may close these issues.

2 participants