What is the best way to serialize ZoneId or ZoneOffset from format +03:00 to format +03.00 using Jackson? Or may be there is another way how to change : to .
ZoneOffset ZoneId custom serialization
263 Views Asked by trom At
2
There are 2 best solutions below
0
trom
On
To resolve this tak I made custom serializer:
object ZoneOffsetSerializer : JsonSerializer<ZoneOffset>() {
override fun serialize(value: ZoneOffset, jsonGenerator: JsonGenerator, serializers: SerializerProvider) {
val result = "0".takeIf { value.totalSeconds == 0 } ?: value.toString().replace(':', '.')
jsonGenerator.writeString(result)
}
}
and used annotation @JsonSerialize(using = ZoneOffsetSerializer::class) for necessary fields
Related Questions in JAVA
- Add image to JCheckBoxMenuItem
- How to access invisible Unordered List element with Selenium WebDriver using Java
- Inheritance in Java, apparent type vs actual type
- Java catch the ball Game
- Access objects variable & method by name
- GridBagLayout is displaying JTextField and JTextArea as short, vertical lines
- Perform a task each interval
- Compound classes stored in an array are not accessible in selenium java
- How to avoid concurrent access to a resource?
- Why does processing goes slower on implementing try catch block in java?
- Redirect inside java interceptor
- Push toolbar content below statusbar
- Animation in Java on top of JPanel
- JPA - How to query with a LIKE operator in combination with an AttributeConverter
- Java Assign a Value to an array cell
Related Questions in JACKSON
- How do I get the type to convert to when deserializing from Jackson
- Add @JsonAutoDetect to third party lib and firebase Java lib
- How to convert input string to json string or json object using jackson in java
- Why fasterxml lost the "xsi:type" attribute with JaxbAnnotationModule but JAXB Marshaller is fine
- How to covert JSON field name to a Java compatible property name while doing Jackson de-serialisation?
- Apply default serializer to properties in custom serializer with Jackson
- Jackson json to map and camelcase key name
- Robospice and Jackson annotations seems to be ignored
- Trouble outputting Float value using Jackson library for Java
- org.codehaus.jackson.JsonParseException: Unexpected character ('�' (code 65533 / 0xfffd))
- jackson - how to serialize nested object with custom object names?
- Jackson 1.9 @JsonTypeInfo visible discriminator property
- Swagger Dropwizard 0.7 - TextArea for JSON parameter not displayed
- Jackson CSV missing columns
- org.codehaus.jackson versus com.fasterxml.jackson.core
Related Questions in TIMEZONE-OFFSET
- DateTimeOffset parse and custom time zone
- java.time in Scala - Getting UTC offset from Time Zone
- How to Convert a Time to local Time in Different TimeZone
- getting time zone offset in seconds in Python
- Is it important that my server has correct locale-specific timezone set?
- AIX numeric time zone offset
- Get Zenith value and GMT Offset by IP, latitude and longitude
- Is it possible to calculate a local date from a UTC time representing a local midnight?
- How to get default ZoneOffset in Java 8?
- How to keep same date even if time zone is changed
- get timezone abbreviation for arbitrary time in arbitrary locale
- How to store a timestamp with UTC timezone offset in Java 6 without modifying anything?
- How to calculate UTC offset from IANA timezone name in C
- PHP to Python conversion to get timezone offset
- Converting Date to CurrentCompany timeZone in Dynamics ax x++
Related Questions in JSON-SERIALIZATION
- ASP.NET Web API: JSON Serializing Circular References
- Make names of named tuples appear in serialized JSON responses
- Json formatting with Json.net in C#
- How to serialize JsonSubType with child interface instead of subclass?
- How to convert nested object into Json in Delphi 10.1 berlin
- Json.Net - adapt dictionary key serialization for single property
- "JsonException: The JSON value could not be converted to NodaTime.Instant" NodaTime issue with ASP.NET Core 3.1 Razor Page web application
- Nestjs serialization in validation pipe not working
- Flutter JSON serialization and Setters
- ASP.NET Core 7 Web API - how to serialize in Pascal case?
- How to fromJSON/toJSON of Geopoints or custom datatypes in Flutter using Freezed and Firebase (Have always build errors)
- Serialize ArrayList using hypersistence-utils
- Could not write JSON: Infinite recursion (StackOverflowError)]
- .NET properties in derived class are not serialized by default using Json.Net
- Serialization and deserialization of single value java object in microservice API module
Related Questions in ZONEID
- How to use locale for Java ZoneId?
- Many instances of java.time.ZoneRegion in Java heap. Isn't ZoneId instances supposed to be cached?
- how to manage the timezone which are not directly supported in java
- ZoneOffset ZoneId custom serialization
- Java Timezone issue with LocalDate not showing correct date
- Is there any way to convert ZoneOffset to ZoneId in Java 8?
- Failing to convert from epochmili to string
- LocalDateTime with minimum LocalDate and Timezone (ZoneId.SYSTEM)
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
The zone offset,
+03:00is already in the ISO 8601 standard format. Therefore, you should educate the publisher/consumer to stick to it. However, if you want to change it in the desired format for any reason, here is how you can do it:Output:
Learn more about the modern Date-Time API from Trail: Date Time.