-
Notifications
You must be signed in to change notification settings - Fork 18
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
Parent class generic collection field not working #124
Comments
I'll try to dig and fing the issue, but thats difficult to navigate in processors looking at project first time, so this may took some time for me |
Don't worry will take a look, thanks for the good report |
Hmm I added a test and it passed #127 Can you provide a sample project? |
Hello, yes my bad, I didn't properly checked test myself, thought the problem is just with List/Collection parent types, case is a bit complex, thats when the generic type is complex itself, here some tests below that represent my situation In my project I had the same case, when parent have List type and the T type is actually some other DTO class, hope this tests below illustrates the issue I faced. I checked tests below they fail. May be tests are inaccurate or I did something wrong actually void 'generic complex collection member supertype serialize'() {
given:
def compiled = buildContext('example.Sub', '''
package example;
import io.micronaut.core.annotation.Introspected;
import io.micronaut.serde.annotation.Serdeable;
import java.util.List;
@Serdeable
class Typo {
public String name;
}
@Serdeable
class Sub extends Sup<Typo> {
}
@Serdeable
@Introspected(accessKind = Introspected.AccessKind.FIELD)
class Sup<T> {
public List<T> value;
}
''')
def baseClass = compiled.classLoader.loadClass('example.Sub')
def a = newInstance(compiled, 'example.Sub')
def typo = newInstance(compiled, 'example.Typo')
typo.name = "Bob"
a.value = Arrays.asList(typo);
expect:
serializeToString(jsonMapper, a, baseClass) == '{"value":[{"name":"Bob"}]}'
}
void 'generic complex collection member supertype deserialize'() {
given:
def compiled = buildContext('example.Sub', '''
package example;
import io.micronaut.core.annotation.Introspected;
import io.micronaut.serde.annotation.Serdeable;
import java.util.List;
@Serdeable
class Typo {
public String name;
}
@Serdeable
class Sub extends Sup<Typo> {
}
@Serdeable
@Introspected(accessKind = Introspected.AccessKind.FIELD)
class Sup<T> {
public List<T> value;
}
''')
expect:
def baseClass = compiled.classLoader.loadClass('example.Sub')
deserializeFromString(jsonMapper, baseClass, '{"value":[{"name":"Bob"}]}').value.get(0).name == 'Bob'
}
|
Issue was unrelated to generics, you were missing the access kind field declaration for child classes ccf5385 |
Expected Behavior
When we have class that is like:
And its child extends such class:
Expecting serialization works properly, not 100% sure that you will support such case, but looks like legit one (this is expected to any Collection like, Collection, Set, List interfaces)
I see that it could be like and work successfully:
But some times that's not the case in some DTOs behavior/design
Actual Behaviour
Tests from above fails with:
Steps To Reproduce
Here is test that reproduces this issue as analog to (
micronaut-serialization/serde-jackson/src/test/groovy/io/micronaut/serde/jackson/object/ObjectSerdeSpec.groovy
Lines 2161 to 2182 in fc7da41
Environment Information
Just cloned repo, added this test and run
Example Application
No response
Version
3.3.0
The text was updated successfully, but these errors were encountered: