generated from micronaut-projects/micronaut-project-template
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert configuration to beans (#561)
- Loading branch information
Showing
7 changed files
with
413 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
serde-api/src/main/java/io/micronaut/serde/config/DefaultDeserializationConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
serde-api/src/main/java/io/micronaut/serde/config/DefaultSerdeConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.