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

Test and fix for StackOverflowError on missing serde #114

Merged
merged 1 commit into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
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
@@ -0,0 +1,25 @@
package io.micronaut.serde.jackson.errors

import io.micronaut.serde.ObjectMapper
import io.micronaut.serde.exceptions.SerdeException
import io.micronaut.serde.jackson.JsonCompileSpec
import io.micronaut.test.extensions.spock.annotation.MicronautTest
import jakarta.inject.Inject
import spock.lang.Specification

@MicronautTest
class NoSerdeSpec extends Specification {
@Inject ObjectMapper objectMapper

void "test error when no serde is present"() {
when:
objectMapper.writeValueAsString(new Foo())

then:
def e = thrown(SerdeException)
e.message == 'No serializable introspection present for type Foo. Consider adding Serdeable.Serializable annotate to type Foo. Alternatively if you are not in control of the project\'s source code, you can use @SerdeImport(Foo.class) to enable serialization of this type.'
}
static class Foo {}
}


Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,17 @@ public boolean isAbsent(Object value) {
// no introspection, create dynamic serialization case
return (encoder, context, value, argument) -> {
final Class<Object> theType = (Class<Object>) value.getClass();
final Argument<Object> t = Argument.of(
theType,
argument.getAnnotationMetadata()
);
context.findSerializer(t)
.createSpecific(t, encoderContext)
.serialize(encoder, context, value, t);
if (!theType.equals(type.getType())) {
final Argument<Object> t = Argument.of(
theType,
argument.getAnnotationMetadata()
);
context.findSerializer(t)
.createSpecific(t, encoderContext)
.serialize(encoder, context, value, t);
} else {
throw new SerdeException(e.getMessage(), e);
}
};
}
final AnnotationMetadata annotationMetadata = type.getAnnotationMetadata();
Expand Down