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

Globally disabling getters and setters #44

Closed
butlnor opened this issue Mar 19, 2015 · 9 comments
Closed

Globally disabling getters and setters #44

butlnor opened this issue Mar 19, 2015 · 9 comments
Assignees
Milestone

Comments

@butlnor
Copy link

butlnor commented Mar 19, 2015

Hello!

I our project repository we have thousands of classes, and not all were written conforming to the getter/setter patterns. This was not even required or necessary.

However, gwt-jackson by default processes such non-getter methods that start with "get***". As many such methods are not meant to be used outside of their contexts, they generate an error when called by gwt-jackson.

I know about @JsonAutoDetect. But I don't want to write annotations (or use mixin annotations) for 1000 classes!

Is there a way, to globally configure gwt-jackson for all types, to NEVER process getters and setters, and ONLY use fields?

@nmorel
Copy link
Owner

nmorel commented Mar 19, 2015

The only available way is to use a mixin annotation on java.lang.Object.

Though, I should be able to add a global configuration in AbstractConfiguration.

@butlnor
Copy link
Author

butlnor commented Mar 19, 2015

Thanks.

I tried with just Object, but then I got too many errors and warnings, which otherwise don't happen (if I annotate some tens of classes, which I use and don't want to use their setters and getters). We have many really complex classes, which were initially not meant for JSON, so it's likely their fault. It's my responsibility to fix them.

However, stack overflow happens, if an object has itself as a field, like the linked lists or trees do have.

@butlnor
Copy link
Author

butlnor commented Mar 19, 2015

I meant stack overflow while GWT is rebinding at the startup, not at runtime.

Caused by: java.lang.StackOverflowError: null
at com.google.gwt.dev.util.collect.HashMap.keyHashCode(HashMap.java:640)
at com.google.gwt.dev.util.collect.HashMap.getKeyIndex(HashMap.java:767)
at com.google.gwt.dev.util.collect.HashMap.findKey(HashMap.java:696)
at com.google.gwt.dev.util.collect.HashMap.get(HashMap.java:463)
at com.google.gwt.dev.javac.typemodel.JPackage.findTypeImpl(JPackage.java:108)
at com.google.gwt.dev.javac.typemodel.JPackage.findType(JPackage.java:47)
at com.google.gwt.dev.javac.typemodel.JPackage.findType(JPackage.java:42)
at com.google.gwt.dev.javac.typemodel.TypeOracle.findType(TypeOracle.java:387)
at com.google.gwt.dev.javac.typemodel.TypeOracle.findType(TypeOracle.java:68)
at com.google.gwt.dev.javac.StandardGeneratorContext.tryCreate(StandardGeneratorContext.java:830)
at com.github.nmorel.gwtjackson.rebind.AbstractCreator.getPrintWriter(AbstractCreator.java:93)
at com.github.nmorel.gwtjackson.rebind.AbstractBeanJsonCreator.create(AbstractBeanJsonCreator.java:156)
at com.github.nmorel.gwtjackson.rebind.AbstractCreator.getJsonSerializerFromType(AbstractCreator.java:244)
at com.github.nmorel.gwtjackson.rebind.AbstractCreator.getJsonSerializerFromType(AbstractCreator.java:258)
at com.github.nmorel.gwtjackson.rebind.AbstractCreator.getJsonSerializerFromType(AbstractCreator.java:258)
at com.github.nmorel.gwtjackson.rebind.AbstractCreator.getJsonSerializerFromType(AbstractCreator.java:258)
...

@nmorel
Copy link
Owner

nmorel commented Mar 19, 2015

I don't understand how you get a stackoverflow. Do you have an example ?

You also changed the auto detection for field to detect more than public fields ?

@butlnor
Copy link
Author

butlnor commented Mar 19, 2015

I wrote this:

@JsonAutoDetect(
    fieldVisibility = Visibility.ANY, 
    creatorVisibility = Visibility.ANY, 
    getterVisibility = Visibility.NONE, 
    setterVisibility = Visibility.NONE, 
    isGetterVisibility = Visibility.NONE)
private static class FieldsOnlyMixin {
}

@Override
protected void configure() {
    addMixInAnnotations(Object.class, FieldsOnlyMixin.class);
}

@butlnor
Copy link
Author

butlnor commented Mar 19, 2015

However, regarding the stack overflow, it's strange. I made a copy of the problematic class, to find which field or method causes problems, but the copy worked. So it seems it has something to do with the type hierarchy, as many other classes extend this one. Will try to analyze and will inform you soon.

The class and it's hierarchy is too complex to send it as an example. It has one String id field, and parent of the same type as the object, but many methods, which start with "get" or "is".

Thanks for all the info.

@butlnor butlnor closed this as completed Mar 23, 2015
@butlnor
Copy link
Author

butlnor commented Mar 28, 2015

I found a reason for stack overflow. It happens with parameterized classes that use themselves as a parameter, like:

interface IdentifiableEntity<T extends IdentifiableEntity<T>>

@nmorel
Copy link
Owner

nmorel commented Mar 28, 2015

Thanks, I'll look into it!

@nmorel nmorel reopened this Mar 28, 2015
@nmorel nmorel added this to the 1.0.0 milestone Mar 30, 2015
@nmorel nmorel self-assigned this Mar 30, 2015
@nmorel nmorel modified the milestones: 0.9.1, 1.0.0 Mar 31, 2015
@nmorel
Copy link
Owner

nmorel commented Mar 31, 2015

You can now configure the default behaviour via a global configuration. Watch this wiki page to find how to add your custom configuration.

@nmorel nmorel closed this as completed Mar 31, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants