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

JsonIgnore seems to be ignored #102

Open
Hadesskywalker opened this issue Jan 31, 2017 · 2 comments
Open

JsonIgnore seems to be ignored #102

Hadesskywalker opened this issue Jan 31, 2017 · 2 comments
Assignees
Labels

Comments

@Hadesskywalker
Copy link

Hi,

I am not sure the following should happen as it does?
I hab a problem, where some fields in my class did not appear in the json, as if they were completely ignored. It seems that JsonIgnore has priority over JsonProperty.

Im using gwt-jackson 0.14.1 and jackson 2.8.2 (but seems to happen with older versions too)

The method sequence seems to matter.

Case 0:

works

@JsonProperty("internal_html_page_identifier")
public String getInternal_html_page_identifier() {
	return internal_html_page_identifier;
}

@JsonProperty("external_link_address")
public String getExternal_link_address() {
	return external_link_address;
}
	
public boolean isExternal_link_address() {
	return external_link_address != null;
}

public boolean isInternal_html_page_identifier() {
	return internal_html_page_identifier != null;
}

Case 1:

internal_html_page_identifier and external_link_address are completely ignored when sending data from gwt to the server (the other way around seems fine)

@JsonProperty("internal_html_page_identifier")
public String getInternal_html_page_identifier() {
	return internal_html_page_identifier;
}

@JsonProperty("external_link_address")
public String getExternal_link_address() {
	return external_link_address;
}
	
@JsonIgnore
public boolean isExternal_link_address() {
	return external_link_address != null;
}

@JsonIgnore
public boolean isInternal_html_page_identifier() {
	return internal_html_page_identifier != null;
}

Case 2:

Can't be compiled

@JsonIgnore
public boolean isExternal_link_address() {
	return external_link_address != null;
}

@JsonIgnore
public boolean isInternal_html_page_identifier() {
	return internal_html_page_identifier != null;
}

@JsonProperty("internal_html_page_identifier")
public String getInternal_html_page_identifier() {
	return internal_html_page_identifier;
}

@JsonProperty("external_link_address")
public String getExternal_link_address() {
	return external_link_address;
}

Error Message:

Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
         Adding '2' new generated units
            See snapshot: /tmp/at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl2581841548089664328.java
            Ignored 1 unit with compilation errors in first pass.
Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
         [ERROR] Errors in '/tmp/gwt-codeserver-6413255898653602665.tmp/at.luxactive.base.base/compile-2/gen/at/luxactive/common/model/impl/MenuItemAdditionsBeanJsonDeserializerImpl.java'
            [ERROR] Line 227: Cannot cast from String to Boolean
            [ERROR] Line 233: Cannot cast from String to Boolean
            [ERROR] Line 291: Type mismatch: cannot convert from String to boolean
            [ERROR] Line 297: Type mismatch: cannot convert from String to boolean
            [ERROR] Line 335: The constructor MenuItemAdditions(int, Date, int, String, int, boolean, boolean, int, String, boolean) is undefined
            See snapshot: /tmp/at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl2686319644399262517.java
         Tracing compile failure path for type 'at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl'
            [ERROR] Errors in '/tmp/gwt-codeserver-6413255898653602665.tmp/at.luxactive.base.base/compile-2/gen/at/luxactive/common/model/impl/MenuItemAdditionsBeanJsonDeserializerImpl.java'
               [ERROR] Line 233: Cannot cast from String to Boolean
               [ERROR] Line 227: Cannot cast from String to Boolean
               [ERROR] Line 291: Type mismatch: cannot convert from String to boolean
               [ERROR] Line 335: The constructor MenuItemAdditions(int, Date, int, String, int, boolean, boolean, int, String, boolean) is undefined
               [ERROR] Line 297: Type mismatch: cannot convert from String to boolean
         [ERROR] Hint: Check that the type name 'at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl' is really what you meant
         [ERROR] Hint: Check that your classpath includes all required source roots
         Unification traversed 1927 fields and methods and 1665 types. 22 are considered part of the current module and 39 had all of their fields and methods traversed.
         [WARN] Some stale types ([at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonSerializerImpl$9, at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonSerializerImpl$10, at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl, at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl$5, at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl$4, at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl$3, at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl$2, at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl$1, at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl$11, at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl$10, at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl$9, at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl$8, at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl$7, at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl$6]) were not reprocessed as was expected. This is either a compiler bug or a Generator has legitimately stopped creating these types.
      [ERROR] Compiler returned false
      [WARN] recompile failed
      [WARN] continuing to serve previous version

Case 3:

Can't be compiled

public boolean isExternal_link_address() {
	return external_link_address != null;
}

public boolean isInternal_html_page_identifier() {
	return internal_html_page_identifier != null;
}

@JsonProperty("internal_html_page_identifier")
public String getInternal_html_page_identifier() {
	return internal_html_page_identifier;
}

@JsonProperty("external_link_address")
public String getExternal_link_address() {
	return external_link_address;
}

Error Message:

Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
         Adding '7' new generated units
            See snapshot: /tmp/at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl9141075960507233253.java
            Ignored 1 unit with compilation errors in first pass.
Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
         Adding '2' new generated units
            See snapshot: /tmp/at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl1960291141095246487.java
            Ignored 1 unit with compilation errors in first pass.
Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
         [ERROR] Errors in '/tmp/gwt-codeserver-2852235086553331873.tmp/at.luxactive.base.base/compile-2/gen/at/luxactive/common/model/impl/MenuItemAdditionsBeanJsonDeserializerImpl.java'
            [ERROR] Line 227: Cannot cast from String to Boolean
            [ERROR] Line 233: Cannot cast from String to Boolean
            [ERROR] Line 291: Type mismatch: cannot convert from String to boolean
            [ERROR] Line 297: Type mismatch: cannot convert from String to boolean
            [ERROR] Line 335: The constructor MenuItemAdditions(int, Date, int, String, int, boolean, boolean, int, String, boolean) is undefined
            See snapshot: /tmp/at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl3210719922381735414.java
         Tracing compile failure path for type 'at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl'
            [ERROR] Errors in '/tmp/gwt-codeserver-2852235086553331873.tmp/at.luxactive.base.base/compile-2/gen/at/luxactive/common/model/impl/MenuItemAdditionsBeanJsonDeserializerImpl.java'
               [ERROR] Line 233: Cannot cast from String to Boolean
               [ERROR] Line 227: Cannot cast from String to Boolean
               [ERROR] Line 291: Type mismatch: cannot convert from String to boolean
               [ERROR] Line 335: The constructor MenuItemAdditions(int, Date, int, String, int, boolean, boolean, int, String, boolean) is undefined
               [ERROR] Line 297: Type mismatch: cannot convert from String to boolean
         [ERROR] Hint: Check that the type name 'at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl' is really what you meant
         [ERROR] Hint: Check that your classpath includes all required source roots
         Unification traversed 1943 fields and methods and 1667 types. 24 are considered part of the current module and 41 had all of their fields and methods traversed.
         [WARN] Some stale types ([at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl, at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl$5, at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl$4, at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl$3, at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl$2, at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl$1, at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl$11, at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl$10, at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl$9, at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl$8, at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl$7, at.luxactive.common.model.impl.MenuItemAdditionsBeanJsonDeserializerImpl$6]) were not reprocessed as was expected. This is either a compiler bug or a Generator has legitimately stopped creating these types.
      [ERROR] Compiler returned false
      [WARN] recompile failed
      [WARN] continuing to serve previous version
@nmorel nmorel self-assigned this Jan 31, 2017
@nmorel nmorel added the bug label Jan 31, 2017
@nmorel
Copy link
Owner

nmorel commented Jan 31, 2017

Case 1 & 2 should work I think. Not sure about case 3.
I'll have to test those with Jackson to compare.
Thanks for the detailed test cases :)

@Hadesskywalker
Copy link
Author

I tinkered a little bit further today, it seems to be based on the existing setter method.

String GET_X();
boolean IS_X();
SET_X(boolean);

This can't be compiled in GWT.
[ERROR] Line 354: The method setUsedForAllLanguages(boolean) in the type ActivityImage is not applicable for the arguments (String)

From my first cases, Case 0 works but Case 1 seems (to me) more intuitive.

String GET_X(); > JsonProperty
boolean IS_X(); > JsonIgnore
SET_X(String);

So not to have the JsonIgnore overwrite the explicitly set JsonPrperty.
That way I know what I want to ignore and what I want to be parsed (upper Case 1). And leaving the IS_X not annotated to be an implicit ignore (upper Case 0). (Not sure if this would go against any previous design decisions)

Hopefully this helps, and thank you for your work!

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

No branches or pull requests

2 participants