Giter Site home page Giter Site logo

Comments (16)

nmorel avatar nmorel commented on July 29, 2024

To reproduce, I just need a class class A<T extends A> annotated with @JsonIgnoreType and a second class having class A in a field ?

I'm not sure what you can do. I normally don't parse children of Objet unless they are explicitly whitelisted. Which version do you use ? I had a bug on Serializable class which is fixed in the current snapshot.

from gwt-jackson.

butlnor avatar butlnor commented on July 29, 2024

Yes, we have different self-parameterized classes, but also java's Enum can be listed as a cause of stack overflow, as Enum is in fact Enum<E extends Enum<E>>.

We have tried to use custom serializers for those unbounded generic classes (like Abc), but it seems that gwt-jackson first analyzes the class hierarchy, before starting to generate the mappers and using custom serializers.

I have put some System.out.println into JTypeName.java, to log the visited classes, to trace what is happening.
And as said, just the fact that some problematic class is on the classpath, and never used for the serialization, causes stack overflow, when matching Object or fields. This means that if I have some java bean, with some Abc field, every known class will be processed as a possible candidate for "?". Because I saw many GWT UI classes, like ListBox etc, which are never serialized, not even referenced by the serialization classes, but were listed in the console.

I must mention, that this happens with GWT unit tests. Currently we cannot try this in the normal hosted mode in the browser.

from gwt-jackson.

butlnor avatar butlnor commented on July 29, 2024

The annotation @JsonIgnoreType is not even necessary to reproduce the problem. I just think that gwt-jackson should stop processing the class hierarchy when it finds a class, annotated with @JsonIgnoreType.

from gwt-jackson.

butlnor avatar butlnor commented on July 29, 2024

I am using the latest official version, 0.9.0.

from gwt-jackson.

butlnor avatar butlnor commented on July 29, 2024

Example:

public class Abc<T> {
}

public class SomeBean {
public Abc<?> abc;
}

This will match every known class as a type for Abc. So it will process all known classes, until some problematic one is found and causes stack overflow. So some class A<T extends A> will be processed, even if not explicitly referenced anywhere.

from gwt-jackson.

nmorel avatar nmorel commented on July 29, 2024

What hierarchy do you have on your self-parameterized classes ?

I can reproduce the stackoverflow with :

public static class Toto {
    public Tata<?> huhu;
}

public static class Tata<T extends Tata> {
    public T tutu;
}

But if I add the @JsonIgnoreType, the error disappear.

from gwt-jackson.

nmorel avatar nmorel commented on July 29, 2024

Managed to reproduce it with a supertype :

public static class Toto {
    public Tutu tutu;
}

public static class Tutu {

}

@JsonIgnoreType
public static class Tata<T extends Tata> extends Tutu {
    public T tata;
}

To (de)serialize Tutu, I parse all its children to create deserializer. I guess I don't filter out type annotated with @JsonIgnoreType.

from gwt-jackson.

nmorel avatar nmorel commented on July 29, 2024

It should be fixed, at least the case I was able to reproduce. Can you test the snapshot ?

from gwt-jackson.

butlnor avatar butlnor commented on July 29, 2024

For Tata, you don't even need to extend Tutu. Just the mere fact that self-referencing Tata is in the classpath, is enough to be somehow found, causing the stack overflow. The problem with the stack overflow itself was already mentioned in another issue, here the issue is that completely unreferenced classes are processed.

I am not sure if completely unused classes are also processed, but I can guarantee that the classes, that are used somewhere (like in UI), but not in the JSON serialization logic, are still processed.

If I don't have any unbounded class or Object in the serialization logic, then only the limited number of directly referenced classes are processed.

from gwt-jackson.

butlnor avatar butlnor commented on July 29, 2024

Have tried with the latest master revision, but it's the same stack overflow. The stack trace is completely the same as in issue #48.

I might help if there would be some additional optional setting (in .gwt.xml), to limit the classpaths or packages where to search for the classes. Like gwtJacksonClasspaths="com.xxx.yyy;com.xxx.zzz".

from gwt-jackson.

nmorel avatar nmorel commented on July 29, 2024

You have the stack overflow even with the self-referencing types annotated with @JsonIgnoreType ?

I still have the stack overflow but only when the @JsonIgnoreType is not set in my test case.

from gwt-jackson.

butlnor avatar butlnor commented on July 29, 2024

It crashes when encountering Enum<E extends Enum<E>>, which I cannot annotate, since it's part of JRE. But will try with a mixin for Enum.

A note: we never reference Enum<?> in any of our json serializable classes.

from gwt-jackson.

butlnor avatar butlnor commented on July 29, 2024

No, registering a mixin with @JsonIgnoreType for Enum doesn't help. Still stack overflow.

@JsonIgnoreType
private static class EnumMixIn {
}
...
addMixInAnnotations(Enum.class, EnumMixIn.class);

from gwt-jackson.

butlnor avatar butlnor commented on July 29, 2024

However, with the snapshot, the classes directly annotated with @JsonIgnoreType are ignored, thanks.

from gwt-jackson.

butlnor avatar butlnor commented on July 29, 2024

The problem with Enum was, that many UI-only classes were parameterized with Enum, like EnumListBox<T extends Enum<?>>.
When I annotated all those problematic classes with @JsonIgnoreType, they were ignored, and the unit test succeeded. No more stack overflow.

But annotating self-parameterized interfaces doesn't work, I had to annotate all the implemented classes.

However, annotating UI classes with @JsonIgnoreType is not really nice. Registering a mixin with @JsonIgnoreType didn't work for Enum, I rather had to ignore all the classes parameterized with Enum.
Is it possible to implement such mixins?

from gwt-jackson.

nmorel avatar nmorel commented on July 29, 2024

It's odd it didn't work on interface, I'm normally looking for annotations on all hierarchy.
I'll look next week when I have more spare time.

from gwt-jackson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.