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

Upgrade to Micronaut 3.5 #246

Merged
merged 7 commits into from
Jul 21, 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
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
projectVersion=1.1.1-SNAPSHOT
projectVersion=1.2.0-SNAPSHOT
projectGroup=io.micronaut.serde
micronautDocsVersion=2.0.0
micronautVersion=3.4.4
micronautVersion=3.5.3
micronautTestVersion=3.0.5
groovyVersion=3.0.9
spockVersion=2.0-groovy-3.0
Expand All @@ -14,7 +14,7 @@ githubSlug=micronaut-projects/micronaut-serialization
developers=Graeme Rocher

# Micronaut core branch for BOM pull requests
githubCoreBranch=3.5.x
githubCoreBranch=3.6.x
bomProperty=micronautSerializationVersion
org.gradle.caching=true
org.gradle.jvmargs=-XX:MaxMetaspaceSize=1g
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ managed-jakarta-json-bindApi = "2.0.0"
managed-glassfish-jakarta-json = "2.0.1"

oracle-jdbc-driver = "21.6.0.0.1"
jetbrains-annotations = "23.0.0"

[libraries]
managed-bson = { module = "org.mongodb:bson", version.ref = "managed-bson" }
Expand All @@ -14,3 +15,4 @@ managed-jakarta-json-api = { module = "jakarta.json:jakarta.json-api", version.r
managed-jakarta-json-bindApi = { module = "jakarta.json.bind:jakarta.json.bind-api", version.ref = "managed-jakarta-json-bindApi" }

oracle-jdbc-driver = { module = "com.oracle.database.jdbc:ojdbc8", version.ref = "oracle-jdbc-driver" }
jetbrains-annotations = { module = "org.jetbrains:annotations", version.ref = "jetbrains-annotations" }
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class BsonMappingSpec extends Specification implements BsonJsonSpec, BsonBinaryS
when:
def json = bsonJsonMapper.writeValueAsString(e)
then:
json == """{"rename-compile-time": "val1", "bar yes": "val2", "notRenamedProperty": "test", "_xyz": null, "rename-compile-time": "val1"}"""
json == """{"rename-compile-time": "val1", "bar yes": "val2", "notRenamedProperty": "test", "_xyz": null}"""
when:
def value = bsonJsonMapper.readValue("""{"_xyz": "abc"}""", NamingStrategiesEntity)
then:
Expand Down Expand Up @@ -564,4 +564,4 @@ class MappedCodec<T> implements Codec<T> {
Class<T> getEncoderClass() {
return type
}
}
}
4 changes: 3 additions & 1 deletion serde-bson/src/test/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@
<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>

<logger name="io.micronaut.context.condition" level="trace" />
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class JsonCompileSpec extends AbstractTypeElementSpec implements JsonSpec {
ApplicationContext context =
buildContext(className, source, true)

setupSerdeRegistry(context)
jsonMapper = context.getBean(ObjectMapper)

def t = context.classLoader
Expand Down Expand Up @@ -89,82 +88,24 @@ class JsonCompileSpec extends AbstractTypeElementSpec implements JsonSpec {
buildContext("test.Source" + System.currentTimeMillis(), source, true)


setupSerdeRegistry(context)
jsonMapper = context.getBean(JsonMapper)
return context
}

@Override
ApplicationContext buildContext(String className, @Language("java") String cls, boolean includeAllBeans) {
def context = super.buildContext(className, cls, true)
setupSerdeRegistry(context)
jsonMapper = context.getBean(JsonMapper)
return context
}

@Override
ApplicationContext buildContext(String className, @Language("java") String cls) {
def context = super.buildContext(className, cls, true)
setupSerdeRegistry(context)
def t = context.classLoader
.loadClass(className)
typeUnderTest = Argument.of(t)
jsonMapper = context.getBean(JsonMapper)
return context
}

protected void setupSerdeRegistry(ApplicationContext context) {
def classLoader = context.classLoader
// horrible hack this
def f = ReflectionUtils.getRequiredField(classLoader.getClass(), "files")
f.setAccessible(true)
def files = f.get(classLoader)
def resolvedTypes = files.findAll({ JavaFileObject jfo ->
jfo.name.contains('$IntrospectionRef')
}).collect( { JavaFileObject jfo ->
String className = jfo.name.substring(14, jfo.name.length() - 6).replace('/', '.')
classLoader.loadClass(className)
})


def references = resolvedTypes
.collect() {
(BeanIntrospectionReference) InstantiationUtils.instantiate(it)
}

context.registerSingleton(SerdeIntrospections, new DefaultSerdeIntrospections() {

@Override
BeanIntrospector getBeanIntrospector() {
return new BeanIntrospector() {
@Override
Collection<BeanIntrospection<Object>> findIntrospections(@NonNull Predicate<? super BeanIntrospectionReference<?>> filter) {
return references.stream()
.filter(filter)
.filter(BeanIntrospectionReference::isPresent)
.map(BeanIntrospectionReference::load)
.collect(Collectors.toList()) + SHARED.findIntrospections(filter)
}

@Override
Collection<Class<?>> findIntrospectedTypes(@NonNull Predicate<? super BeanIntrospectionReference<?>> filter) {
return Collections.emptySet()
}

@Override
def <T> Optional<BeanIntrospection<T>> findIntrospection(@NonNull Class<T> beanType) {
def result = findIntrospections({ ref ->
ref.isPresent() && ref.beanType == beanType
}).stream().findFirst()
if (result.isPresent()) {
return result
} else {
return SHARED.findIntrospection(beanType)
}
}
}
}

})
}
}
Loading