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

add test for #124 #127

Merged
merged 2 commits into from
Feb 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2158,6 +2158,104 @@ class B {
context.close()
}

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
@Introspected(accessKind = Introspected.AccessKind.FIELD)
class Typo {
public String name;
}

@Serdeable
@Introspected(accessKind = Introspected.AccessKind.FIELD)
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
@Introspected(accessKind = Introspected.AccessKind.FIELD)
class Typo {
public String name;
}

@Serdeable
@Introspected(accessKind = Introspected.AccessKind.FIELD)
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'
}


void 'generic collection member supertype'() {
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 Sub extends Sup<String> {
}

@Serdeable
@Introspected(accessKind = Introspected.AccessKind.FIELD)
class Sup<T> {
public List<T> value;
}
''')

expect:
jsonMapper.readValue('{"value":["bar"]}', typeUnderTest).value == ['bar']

cleanup:
compiled.close()
}


void 'generic supertype'() {
given:
def compiled = buildContext('example.Sub', '''
Expand Down