-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use ZoneId instead of String for timezone related configuration
- Loading branch information
Showing
10 changed files
with
94 additions
and
30 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
34 changes: 34 additions & 0 deletions
34
.../java/io/quarkus/deployment/recording/substitutions/AdditionalSubstitutionsBuildStep.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,34 @@ | ||
package io.quarkus.deployment.recording.substitutions; | ||
|
||
import java.time.ZoneId; | ||
|
||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.builditem.ObjectSubstitutionBuildItem; | ||
import io.quarkus.runtime.recording.substitutions.ZoneIdSubstitution; | ||
|
||
public class AdditionalSubstitutionsBuildStep { | ||
|
||
@BuildStep | ||
public void additionalSubstitutions(BuildProducer<ObjectSubstitutionBuildItem> producer) { | ||
zoneIdSubstitutions(producer); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private void zoneIdSubstitutions(BuildProducer<ObjectSubstitutionBuildItem> producer) { | ||
try { | ||
/* | ||
* We can't refer to these classes as they are package private but we need a handle on need | ||
* because the bytecode recorder needs to have the actual class registered and not a super class | ||
*/ | ||
|
||
Class<ZoneId> zoneRegionClass = (Class<ZoneId>) Class.forName("java.time.ZoneRegion"); | ||
producer.produce(new ObjectSubstitutionBuildItem(zoneRegionClass, String.class, ZoneIdSubstitution.class)); | ||
|
||
Class<ZoneId> zoneOffsetClass = (Class<ZoneId>) Class.forName("java.time.ZoneOffset"); | ||
producer.produce(new ObjectSubstitutionBuildItem(zoneOffsetClass, String.class, ZoneIdSubstitution.class)); | ||
} catch (ClassNotFoundException e) { | ||
throw new IllegalStateException("Improper registration of ZoneId substitution", e); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
core/runtime/src/main/java/io/quarkus/runtime/configuration/ZoneIdConverter.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,24 @@ | ||
package io.quarkus.runtime.configuration; | ||
|
||
import static io.quarkus.runtime.configuration.ConverterSupport.DEFAULT_QUARKUS_CONVERTER_PRIORITY; | ||
|
||
import java.io.Serializable; | ||
import java.time.ZoneId; | ||
|
||
import javax.annotation.Priority; | ||
|
||
import org.eclipse.microprofile.config.spi.Converter; | ||
|
||
/** | ||
* A converter to support locales. | ||
*/ | ||
@Priority(DEFAULT_QUARKUS_CONVERTER_PRIORITY) | ||
public class ZoneIdConverter implements Converter<ZoneId>, Serializable { | ||
|
||
private static final long serialVersionUID = -439010527617997936L; | ||
|
||
@Override | ||
public ZoneId convert(final String value) { | ||
return ZoneId.of(value); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
.../runtime/src/main/java/io/quarkus/runtime/recording/substitutions/ZoneIdSubstitution.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,18 @@ | ||
package io.quarkus.runtime.recording.substitutions; | ||
|
||
import java.time.ZoneId; | ||
|
||
import io.quarkus.runtime.ObjectSubstitution; | ||
|
||
public class ZoneIdSubstitution implements ObjectSubstitution<ZoneId, String> { | ||
|
||
@Override | ||
public String serialize(ZoneId obj) { | ||
return obj.getId(); | ||
} | ||
|
||
@Override | ||
public ZoneId deserialize(String str) { | ||
return ZoneId.of(str); | ||
} | ||
} |
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
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
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
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
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
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