SpringBoot — Request data polymorphic mapping (jackson)

In some cases, the server provides an abstract class and multiple implementation classes. When the front-end passes json data to the back-end, we hope that the mapped object data is a specific implementation class object that is distinguished based on a certain characteristic. Article directory Method to realize Example abstract class object Several implementation classes […]

Jackson deserialization

Jackson Jackson is an open source Java serialization and deserialization tool that can serialize Java objects into strings in XML or JSON format, and deserialize strings in XML or JSON format into Java objects. Because it is simple to use, fast, and does not rely on other libraries except JDK, it is used by many […]

Jackson code example

Jackson code example The sample code contains the Date LocalDate LocalDateTime type processing method JavaBean and json conversion bean2json json2bean Convert List to json list2json json2list Map and json conversion map2json json2map pom.xml <project xmlns=”http://maven.apache.org/POM/4.0.0″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”> <modelVersion>4.0.0</modelVersion> <groupId>com.lihaohze</groupId> <artifactId>chap06</artifactId> <version>1.0.0</version> <packaging>jar</packaging> <name>chap06</name> <url>https://mvnrepository.com/</url> <properties> <!– Public configuration –> <maven.compiler.source>21</maven.compiler.source> <maven.compiler.target>21</maven.compiler.target> <maven.compiler.compilerVersion>21</maven.compiler.compilerVersion> <maven.compiler.encoding>utf-8</maven.compiler.encoding> <project.build.sourceEncoding>utf-8</project.build.sourceEncoding> […]

jackson-dataformat-xml

In addition to processing JSON, Jackson can also be used to process XML (jackson-dataformat-xml module), which can easily complete the conversion between Java objects and XML documents. This article mainly introduces the use of Jackson to process XML. The software version used in this article: Java 1.8.0_321, Jackson 2.13.3. 1. Introduction jackson-dataformat-xml simulates JAXB’s “code […]

Gson FastJson Jackson comes out Date LocalDate LocalDateTime date type JSON format string

Gson FastJson Jackson processes Date LocalDate LocalDateTime date type JSON format string Gson processes Date LocalDate LocalDateTime date type JSON format string When using the Gson library to serialize and deserialize objects whose properties are Date, LocalDate and LocalDateTime, You can use annotations to specify how dates are formatted. The Gson library supports the @SerializedName […]

Lombok + Swagger2 +Jackson The second letter of the attribute is uppercase, and the second letter of the field after serialization is lowercase

Article directory 1. Problem Overview 2. Cause analysis: 1. Overview of the problem The original FastJson converter used in the SpringBoot project, with Swagger2 + lombok serialization, the field case is normal, but when it is replaced with fastJson, if the second letter in the original entity is capitalized, the fields returned in the swagger […]

Spring Authorization Server Optimization: Add Jackson Mixin to the Redis value serializer to solve the problem of Redis deserialization failure

Foreword In the article about front-end and back-end separation of authorization code mode, Redis is used to save user authentication information. The value serializer configured in the Redis configuration file is the default Jdk serializer. Although this can also be used, When viewed in the Redis client, the code is garbled (it seems to be). […]

Conversion between Jackson objects and JSON. When passing json, the enumeration type is passed to Integer, and the timestamp is converted to a fixed format time.

Conversion between Jackson object and JSON, when passing json data, the enumeration type is passed to Integer, and the timestamp is converted to a fixed format time 1. Introduction to the problem I recently made a request – third-party customers access our system, provide interfaces, and transfer data in json format. Looking at the interface […]

5 ways to deserialize Jackson generics

package com.zsk.tool.json; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import lombok.Data; import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl; import java.lang.reflect.Type; public class JsonUtil { /** * Thread safe, can be used globally */ public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); static { //If there […]