Skip to content

Commit

Permalink
Convert configuration to beans (#561)
Browse files Browse the repository at this point in the history
  • Loading branch information
dstepanov authored Sep 4, 2023
1 parent 6c13966 commit 14d84f3
Show file tree
Hide file tree
Showing 7 changed files with 413 additions and 12 deletions.
195 changes: 195 additions & 0 deletions config/accepted-api-changes.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,200 @@
"type": "io.micronaut.serde.bson.BsonBinaryMapper",
"member": "Constructor io.micronaut.serde.bson.BsonBinaryMapper(io.micronaut.serde.SerdeRegistry)",
"reason": "Changed in Micronaut Framework 4"
},
{
"type": "io.micronaut.serde.config.$DeserializationConfiguration$Intercepted$Definition$Reference",
"member": "Field $ANNOTATION_METADATA",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$DeserializationConfiguration$Intercepted$Definition$Reference",
"member": "Constructor io.micronaut.serde.config.$DeserializationConfiguration$Intercepted$Definition$Reference()",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$DeserializationConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.core.annotation.AnnotationSource",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$DeserializationConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.inject.BeanContextConditional",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$DeserializationConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.core.annotation.AnnotationMetadataProvider",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$DeserializationConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.core.beans.BeanInfo",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$DeserializationConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.core.annotation.AnnotationMetadataDelegate",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$DeserializationConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.inject.AdvisedBeanType",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$DeserializationConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.core.annotation.AnnotationMetadata",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$DeserializationConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.core.type.ArgumentCoercible",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$DeserializationConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.inject.QualifiedBeanType",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$DeserializationConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.inject.BeanType",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$DeserializationConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.inject.BeanDefinitionReference",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerdeConfiguration$Intercepted$Definition$Reference",
"member": "Field $ANNOTATION_METADATA",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerdeConfiguration$Intercepted$Definition$Reference",
"member": "Constructor io.micronaut.serde.config.$SerdeConfiguration$Intercepted$Definition$Reference()",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerdeConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.core.annotation.AnnotationSource",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerdeConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.inject.BeanContextConditional",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerdeConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.core.annotation.AnnotationMetadataProvider",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerdeConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.core.beans.BeanInfo",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerdeConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.core.annotation.AnnotationMetadataDelegate",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerdeConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.inject.AdvisedBeanType",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerdeConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.core.annotation.AnnotationMetadata",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerdeConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.core.type.ArgumentCoercible",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerdeConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.inject.QualifiedBeanType",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerdeConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.inject.BeanType",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerdeConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.inject.BeanDefinitionReference",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerializationConfiguration$Intercepted$Definition$Reference",
"member": "Field $ANNOTATION_METADATA",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerializationConfiguration$Intercepted$Definition$Reference",
"member": "Constructor io.micronaut.serde.config.$SerializationConfiguration$Intercepted$Definition$Reference()",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerializationConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.core.annotation.AnnotationSource",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerializationConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.inject.BeanContextConditional",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerializationConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.core.annotation.AnnotationMetadataProvider",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerializationConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.core.beans.BeanInfo",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerializationConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.core.annotation.AnnotationMetadataDelegate",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerializationConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.inject.AdvisedBeanType",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerializationConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.core.annotation.AnnotationMetadata",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerializationConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.core.type.ArgumentCoercible",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerializationConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.inject.QualifiedBeanType",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerializationConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.inject.BeanType",
"reason": "Internal"
},
{
"type": "io.micronaut.serde.config.$SerializationConfiguration$Intercepted$Definition$Reference",
"member": "Implemented interface io.micronaut.inject.BeanDefinitionReference",
"reason": "Internal"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2017-2023 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.serde.config;

import io.micronaut.context.annotation.BootstrapContextCompatible;
import io.micronaut.context.annotation.ConfigurationInject;
import io.micronaut.context.annotation.ConfigurationProperties;
import io.micronaut.core.bind.annotation.Bindable;
import io.micronaut.core.util.StringUtils;

/**
* Default implementation of {@link DeserializationConfiguration}.
*
* @author Denis Stepanov
*/
@ConfigurationProperties(DeserializationConfiguration.PREFIX)
@BootstrapContextCompatible
final class DefaultDeserializationConfiguration implements DeserializationConfiguration {
private final boolean ignoreUnknown;
private final int arraySizeThreshold;
private final boolean strictNullable;

@ConfigurationInject
DefaultDeserializationConfiguration(@Bindable(defaultValue = StringUtils.TRUE) boolean ignoreUnknown,
@Bindable(defaultValue = "100") int arraySizeThreshold,
@Bindable(defaultValue = StringUtils.FALSE) boolean strictNullable) {
this.ignoreUnknown = ignoreUnknown;
this.arraySizeThreshold = arraySizeThreshold;
this.strictNullable = strictNullable;
}

@Override
public boolean isIgnoreUnknown() {
return ignoreUnknown;
}

@Override
public int getArraySizeThreshold() {
return arraySizeThreshold;
}

@Override
public boolean isStrictNullable() {
return strictNullable;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Copyright 2017-2023 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.serde.config;

import io.micronaut.context.annotation.BootstrapContextCompatible;
import io.micronaut.context.annotation.ConfigurationInject;
import io.micronaut.context.annotation.ConfigurationProperties;
import io.micronaut.core.bind.annotation.Bindable;
import io.micronaut.serde.LimitingStream;

import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.TimeZone;

/**
* The default implementation of SerdeConfiguration.
*
* @author Denis Stepanov
*/
@ConfigurationProperties(SerdeConfiguration.PREFIX)
@BootstrapContextCompatible
final class DefaultSerdeConfiguration implements SerdeConfiguration {

private final Optional<String> dateFormat;
private final TimeShape timeWriteShape;
private final NumericTimeUnit numericTimeUnit;
private final boolean writeBinaryAsArray;
private final Optional<Locale> locale;
private final Optional<TimeZone> timeZone;
private final List<String> includedIntrospectionPackages;
private final int maximumNestingDepth;

@ConfigurationInject
DefaultSerdeConfiguration(Optional<String> dateFormat,
@Bindable(defaultValue = "STRING") TimeShape timeWriteShape,
@Bindable(defaultValue = "SECONDS") NumericTimeUnit numericTimeUnit,
@Bindable(defaultValue = "true") boolean writeBinaryAsArray,
Optional<Locale> locale,
Optional<TimeZone> timeZone,
@Bindable(defaultValue = "io.micronaut") List<String> includedIntrospectionPackages,
@Bindable(defaultValue = LimitingStream.DEFAULT_MAXIMUM_DEPTH + "") int maximumNestingDepth) {
this.dateFormat = dateFormat;
this.timeWriteShape = timeWriteShape;
this.numericTimeUnit = numericTimeUnit;
this.writeBinaryAsArray = writeBinaryAsArray;
this.locale = locale;
this.timeZone = timeZone;
this.includedIntrospectionPackages = includedIntrospectionPackages;
this.maximumNestingDepth = maximumNestingDepth;
}

@Override
public Optional<String> getDateFormat() {
return dateFormat;
}

@Override
public TimeShape getTimeWriteShape() {
return timeWriteShape;
}

@Override
public NumericTimeUnit getNumericTimeUnit() {
return numericTimeUnit;
}

@Override
public boolean isWriteBinaryAsArray() {
return writeBinaryAsArray;
}

@Override
public Optional<Locale> getLocale() {
return locale;
}

@Override
public Optional<TimeZone> getTimeZone() {
return timeZone;
}

@Override
public List<String> getIncludedIntrospectionPackages() {
return includedIntrospectionPackages;
}

@Override
public int getMaximumNestingDepth() {
return maximumNestingDepth;
}
}
Loading

0 comments on commit 14d84f3

Please sign in to comment.