Skip to content

Commit

Permalink
Micronaut 4.4 changes (#775)
Browse files Browse the repository at this point in the history
* Micronaut 4.4 changes

* fix(deps): update dependency io.micronaut:micronaut-core-bom to v4.4.0

* ignore tck tests

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Sergio del Amo <sergio.delamo@softamo.com>
  • Loading branch information
3 people authored Apr 2, 2024
1 parent 4afc79c commit e016e4e
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 111 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jetbrains-annotations = "24.1.0"
jmh = "1.37"
groovy = "4.0.18"

micronaut = "4.3.11"
micronaut = "4.4.0"
micronaut-platform = "4.3.7"
micronaut-docs = "2.0.0"
micronaut-test = "4.2.1"
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private static void deserializeAndSetPropertyValue(DecoderContext decoderContext
decoderContext.pushManagedRef(
new PropertyReference<>(
derProperty.managedRef,
derProperty.instrospection,
derProperty.introspection,
derProperty.argument,
instance
)
Expand Down Expand Up @@ -314,10 +314,10 @@ private static Object deserializeValue(DecoderContext decoderContext,
*/
private static final class AnyValuesDeserializer {

private final DeserBean.AnySetter<Object> anySetter;
private final DeserBean.AnySetter anySetter;
private Map<String, Object> values;

AnyValuesDeserializer(DeserBean.AnySetter<Object> anySetter) {
AnyValuesDeserializer(DeserBean.AnySetter anySetter) {
this.anySetter = anySetter;
}

Expand Down Expand Up @@ -425,7 +425,7 @@ void injectProperties(Object instance, DecoderContext decoderContext) throws IOE
final PropertyReference<? super Object, ?> ref = decoderContext.resolveReference(
new PropertyReference<>(
property.backRef,
property.instrospection,
property.introspection,
property.argument,
null
)
Expand Down Expand Up @@ -521,7 +521,7 @@ boolean tryConsumeAndSet(String propertyName, Decoder decoder, DecoderContext de
final PropertyReference<? super Object, ?> ref = decoderContext.resolveReference(
new PropertyReference<>(
property.backRef,
property.instrospection,
property.introspection,
property.argument,
instance
)
Expand Down Expand Up @@ -677,7 +677,7 @@ boolean tryConsume(String propertyName, Decoder decoder, DecoderContext decoderC
final PropertyReference<? super Object, ?> ref = decoderContext.resolveReference(
new PropertyReference<>(
property.backRef,
property.instrospection,
property.introspection,
property.argument,
null
)
Expand Down Expand Up @@ -749,7 +749,7 @@ Object[] getValues(DecoderContext decoderContext) throws IOException {
final PropertyReference<? super Object, ?> ref = decoderContext.resolveReference(
new PropertyReference<>(
property.backRef,
property.instrospection,
property.introspection,
property.argument,
null
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import io.micronaut.core.annotation.Order;
import io.micronaut.core.beans.BeanIntrospection;
import io.micronaut.core.beans.BeanMethod;
import io.micronaut.core.beans.BeanProperty;
import io.micronaut.core.beans.UnsafeBeanProperty;
import io.micronaut.core.beans.BeanReadProperty;
import io.micronaut.core.beans.UnsafeBeanReadProperty;
import io.micronaut.core.beans.exceptions.IntrospectionException;
import io.micronaut.core.naming.NameUtils;
import io.micronaut.core.order.OrderUtil;
Expand Down Expand Up @@ -62,7 +62,7 @@

@Internal
final class SerBean<T> {
private static final Comparator<BeanProperty<?, Object>> BEAN_PROPERTY_COMPARATOR = (o1, o2) -> OrderUtil.COMPARATOR.compare(
private static final Comparator<BeanReadProperty<?, Object>> BEAN_PROPERTY_COMPARATOR = (o1, o2) -> OrderUtil.COMPARATOR.compare(
new Ordered() {
@Override
public int getOrder() {
Expand Down Expand Up @@ -122,15 +122,15 @@ public int getOrder() {
Predicate<String> argumentPropertyPredicate = serdeArgumentConf == null ? null : serdeArgumentConf.resolveAllowPropertyPredicate(allowIgnoredProperties);

PropertyNamingStrategy entityPropertyNamingStrategy = getPropertyNamingStrategy(introspection, encoderContext, null);
final Collection<Map.Entry<BeanProperty<T, Object>, AnnotationMetadata>> properties =
introspection.getBeanProperties().stream()
final Collection<Map.Entry<BeanReadProperty<T, Object>, AnnotationMetadata>> properties =
introspection.getBeanReadProperties().stream()
.filter(this::filterProperty)
.sorted(getPropertyComparator())
.sorted(BEAN_PROPERTY_COMPARATOR)
.map(beanProperty -> {
Optional<Argument<?>> constructorArgument = Arrays.stream(introspection.getConstructor().getArguments())
.filter(a -> a.getName().equals(beanProperty.getName()) && a.getType().equals(beanProperty.getType()))
.findFirst();
return constructorArgument.<Map.Entry<BeanProperty<T, Object>, AnnotationMetadata>>map(argument -> new AbstractMap.SimpleEntry<>(
return constructorArgument.<Map.Entry<BeanReadProperty<T, Object>, AnnotationMetadata>>map(argument -> new AbstractMap.SimpleEntry<>(
beanProperty,
new AnnotationMetadataHierarchy(argument.getAnnotationMetadata(), beanProperty.getAnnotationMetadata())
)).orElseGet(() -> new AbstractMap.SimpleEntry<>(
Expand All @@ -139,12 +139,12 @@ public int getOrder() {
));
})
.toList();
final Map.Entry<BeanProperty<T, Object>, AnnotationMetadata> serPropEntry = properties.stream()
final Map.Entry<BeanReadProperty<T, Object>, AnnotationMetadata> serPropEntry = properties.stream()
.filter(bp -> bp.getValue().hasAnnotation(SerdeConfig.SerValue.class) || bp.getValue().hasAnnotation(JACKSON_VALUE))
.findFirst().orElse(null);
if (serPropEntry != null) {
wrapperProperty = null;
BeanProperty<T, Object> beanProperty = serPropEntry.getKey();
BeanReadProperty<T, Object> beanProperty = serPropEntry.getKey();
final Argument<Object> serType = beanProperty.asArgument();
AnnotationMetadata propertyAnnotationMetadata = serPropEntry.getValue();
jsonValue = new PropSerProperty<>(
Expand Down Expand Up @@ -213,8 +213,8 @@ public int getOrder() {
}
});
}
for (Map.Entry<BeanProperty<T, Object>, AnnotationMetadata> propWithAnnotations : properties) {
final BeanProperty<T, Object> property = propWithAnnotations.getKey();
for (Map.Entry<BeanReadProperty<T, Object>, AnnotationMetadata> propWithAnnotations : properties) {
final BeanReadProperty<T, Object> property = propWithAnnotations.getKey();
final Argument<Object> argument = property.asArgument();
final AnnotationMetadata propertyAnnotationMetadata = propWithAnnotations.getValue();
PropertyNamingStrategy propertyNamingStrategy = getPropertyNamingStrategy(property.getAnnotationMetadata(), encoderContext, entityPropertyNamingStrategy);
Expand Down Expand Up @@ -440,10 +440,6 @@ private PropertyNamingStrategy getPropertyNamingStrategy(AnnotationMetadata anno
return namingStrategyClass == null ? defaultNamingStrategy : encoderContext.findNamingStrategy(namingStrategyClass);
}

private Comparator<BeanProperty<?, Object>> getPropertyComparator() {
return BEAN_PROPERTY_COMPARATOR;
}

private String resolveName(AnnotationMetadata propertyAnnotationMetadata,
String name,
@Nullable
Expand Down Expand Up @@ -485,20 +481,19 @@ private PropertyFilter getPropertyFilterIfPresent(@Nullable BeanContext beanCont
return null;
}

private boolean filterProperty(BeanProperty<T, Object> property) {
return !property.isWriteOnly()
&& !property.booleanValue(SerdeConfig.class, SerdeConfig.IGNORED).orElse(false)
private boolean filterProperty(BeanReadProperty<T, Object> property) {
return !property.booleanValue(SerdeConfig.class, SerdeConfig.IGNORED).orElse(false)
&& !property.booleanValue(SerdeConfig.class, SerdeConfig.IGNORED_SERIALIZATION).orElse(false)
&& !property.booleanValue(SerdeConfig.class, SerdeConfig.WRITE_ONLY).orElse(false);
}

static final class PropSerProperty<B, P> extends SerProperty<B, P> {

private final UnsafeBeanProperty<B, P> beanProperty;
private final UnsafeBeanReadProperty<B, P> beanProperty;

public PropSerProperty(SerBean<B> bean, String name, String originalName, Argument<P> argument, AnnotationMetadata annotationMetadata, BeanProperty<B, P> beanProperty) {
public PropSerProperty(SerBean<B> bean, String name, String originalName, Argument<P> argument, AnnotationMetadata annotationMetadata, BeanReadProperty<B, P> beanProperty) {
super(bean, name, originalName, argument, annotationMetadata);
this.beanProperty = (UnsafeBeanProperty<B, P>) beanProperty;
this.beanProperty = (UnsafeBeanReadProperty<B, P>) beanProperty;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class MockSerdeIntrospections extends DefaultSerdeIntrospections {
f.setAccessible(true)
def files = f.get(classLoader)
def resolvedTypes = files.findAll({ JavaFileObject jfo ->
jfo.name.contains('$IntrospectionRef')
jfo.name.contains('$Introspection')
}).collect( { JavaFileObject jfo ->
String className = jfo.name.substring(14, jfo.name.length() - 6).replace('/', '.')
try {
Expand Down Expand Up @@ -108,7 +108,7 @@ class MockSerdeIntrospections extends DefaultSerdeIntrospections {
f.setAccessible(true)
def files = f.get(classLoader)
def resolvedTypes = files.findAll({ JavaFileObject jfo ->
jfo.name.endsWith('$IntrospectionRef.class')
jfo.name.endsWith('$Introspection.class')
}).collect( { JavaFileObject jfo ->
String className = jfo.name.substring(14, jfo.name.length() - 6).replace('/', '.')
classLoader.loadClass(className)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
@ExcludeClassNamePatterns({
"io.micronaut.http.server.tck.tests.hateoas.JsonErrorTest",
"io.micronaut.http.server.tck.tests.hateoas.VndErrorTest",
"io.micronaut.http.server.tck.tests.hateoas.JsonErrorSerdeTest",
"io.micronaut.http.server.tck.tests.constraintshandler.ControllerConstraintHandlerTest",
"io.micronaut.http.server.tck.tests.forms.FormsInputNumberOptionalTest",
"io.micronaut.http.server.tck.tests.forms.FormsSubmissionsWithListsTest",
Expand Down

0 comments on commit e016e4e

Please sign in to comment.