Skip to content

Commit

Permalink
add test for #124 (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher authored Feb 24, 2022
1 parent aa73435 commit c1c4e49
Showing 1 changed file with 98 additions and 0 deletions.
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

0 comments on commit c1c4e49

Please sign in to comment.