[BAEL-19676] - Move articles out of jackson part 3
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
*.class
|
||||
|
||||
#folders#
|
||||
/target
|
||||
/neoDb*
|
||||
/data
|
||||
/src/main/webapp/WEB-INF/classes
|
||||
*/META-INF/*
|
||||
|
||||
# Packaged files #
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
|
||||
# Files
|
||||
/src/main/resources/orderOutput.yaml
|
||||
@@ -1,12 +0,0 @@
|
||||
## Jackson Cookbooks and Examples
|
||||
|
||||
This module contains articles about Jackson.
|
||||
|
||||
### The Course
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
|
||||
### Relevant Articles:
|
||||
- [Working with Tree Model Nodes in Jackson](https://www.baeldung.com/jackson-json-node-tree-model)
|
||||
- [Compare Two JSON Objects with Jackson](https://www.baeldung.com/jackson-compare-two-json-objects)
|
||||
- [Calling Default Serializer from Custom Serializer in Jackson](https://www.baeldung.com/jackson-call-default-serializer-from-custom-serializer)
|
||||
- More articles: [[<-- prev]](/../jackson)
|
||||
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
||||
@@ -5,7 +5,5 @@ This module contains articles about Jackson annotations.
|
||||
### Relevant Articles:
|
||||
- [Guide to @JsonFormat in Jackson](https://www.baeldung.com/jackson-jsonformat)
|
||||
- [More Jackson Annotations](https://www.baeldung.com/jackson-advanced-annotations)
|
||||
- [Jackson Annotation Examples](https://www.baeldung.com/jackson-annotations)
|
||||
- [Jackson – Bidirectional Relationships](https://www.baeldung.com/jackson-bidirectional-relationships-and-infinite-recursion)
|
||||
- [Jackson – Change Name of Field](https://www.baeldung.com/jackson-name-of-property)
|
||||
- [Jackson Ignore Properties on Marshalling](https://www.baeldung.com/jackson-ignore-properties-on-serialization)
|
||||
- [Jackson JSON Views](https://www.baeldung.com/jackson-json-view-annotation)
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
package com.baeldung.jackson.ignore.dtos;
|
||||
|
||||
public class MyDto {
|
||||
|
||||
private String stringValue;
|
||||
private int intValue;
|
||||
private boolean booleanValue;
|
||||
|
||||
public MyDto() {
|
||||
super();
|
||||
}
|
||||
|
||||
public MyDto(final String stringValue, final int intValue, final boolean booleanValue) {
|
||||
super();
|
||||
|
||||
this.stringValue = stringValue;
|
||||
this.intValue = intValue;
|
||||
this.booleanValue = booleanValue;
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
public String getStringValue() {
|
||||
return stringValue;
|
||||
}
|
||||
|
||||
public void setStringValue(final String stringValue) {
|
||||
this.stringValue = stringValue;
|
||||
}
|
||||
|
||||
public int getIntValue() {
|
||||
return intValue;
|
||||
}
|
||||
|
||||
public void setIntValue(final int intValue) {
|
||||
this.intValue = intValue;
|
||||
}
|
||||
|
||||
public boolean isBooleanValue() {
|
||||
return booleanValue;
|
||||
}
|
||||
|
||||
public void setBooleanValue(final boolean booleanValue) {
|
||||
this.booleanValue = booleanValue;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MyDto [stringValue=" + stringValue + ", intValue=" + intValue + ", booleanValue=" + booleanValue + "]";
|
||||
}
|
||||
|
||||
}
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
package com.baeldung.jackson.ignore.dtos;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
|
||||
@JsonInclude(Include.NON_DEFAULT)
|
||||
public class MyDtoIncludeNonDefault {
|
||||
|
||||
private String stringValue;
|
||||
private int intValue;
|
||||
private boolean booleanValue;
|
||||
|
||||
public MyDtoIncludeNonDefault() {
|
||||
super();
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
public String getStringValue() {
|
||||
return stringValue;
|
||||
}
|
||||
|
||||
public void setStringValue(final String stringValue) {
|
||||
this.stringValue = stringValue;
|
||||
}
|
||||
|
||||
public int getIntValue() {
|
||||
return intValue;
|
||||
}
|
||||
|
||||
public void setIntValue(final int intValue) {
|
||||
this.intValue = intValue;
|
||||
}
|
||||
|
||||
public boolean isBooleanValue() {
|
||||
return booleanValue;
|
||||
}
|
||||
|
||||
public void setBooleanValue(final boolean booleanValue) {
|
||||
this.booleanValue = booleanValue;
|
||||
}
|
||||
|
||||
}
|
||||
-54
@@ -1,54 +0,0 @@
|
||||
package com.baeldung.jackson.ignore.dtos;
|
||||
|
||||
public class MyDtoWithSpecialField {
|
||||
|
||||
private String[] stringValue;
|
||||
private int intValue;
|
||||
private boolean booleanValue;
|
||||
|
||||
public MyDtoWithSpecialField() {
|
||||
super();
|
||||
}
|
||||
|
||||
public MyDtoWithSpecialField(final String[] stringValue, final int intValue, final boolean booleanValue) {
|
||||
super();
|
||||
|
||||
this.stringValue = stringValue;
|
||||
this.intValue = intValue;
|
||||
this.booleanValue = booleanValue;
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
public String[] getStringValue() {
|
||||
return stringValue;
|
||||
}
|
||||
|
||||
public void setStringValue(final String[] stringValue) {
|
||||
this.stringValue = stringValue;
|
||||
}
|
||||
|
||||
public int getIntValue() {
|
||||
return intValue;
|
||||
}
|
||||
|
||||
public void setIntValue(final int intValue) {
|
||||
this.intValue = intValue;
|
||||
}
|
||||
|
||||
public boolean isBooleanValue() {
|
||||
return booleanValue;
|
||||
}
|
||||
|
||||
public void setBooleanValue(final boolean booleanValue) {
|
||||
this.booleanValue = booleanValue;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MyDto [stringValue=" + stringValue + ", intValue=" + intValue + ", booleanValue=" + booleanValue + "]";
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.jackson.test;
|
||||
package com.baeldung.jackson.jsonview;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
@@ -4,8 +4,6 @@ This module contains articles about Jackson conversions.
|
||||
|
||||
### Relevant Articles:
|
||||
- [Mapping a Dynamic JSON Object with Jackson](https://www.baeldung.com/jackson-mapping-dynamic-object)
|
||||
- [Jackson Unmarshalling JSON with Unknown Properties](https://www.baeldung.com/jackson-deserialize-json-unknown-properties)
|
||||
- [Ignore Null Fields with Jackson](https://www.baeldung.com/jackson-ignore-null-fields)
|
||||
- [Mapping Multiple JSON Fields to a Single Java Field](https://www.baeldung.com/json-multiple-fields-single-java-field)
|
||||
- [Convert XML to JSON Using Jackson](https://www.baeldung.com/jackson-convert-xml-json)
|
||||
- [Converting JSON to CSV in Java](https://www.baeldung.com/java-converting-json-to-csv)
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
## Jackson Custom Conversions
|
||||
|
||||
This module contains articles about Jackson custom conversions.
|
||||
|
||||
### Relevant Articles:
|
||||
- [Jackson – Custom Serializer](https://www.baeldung.com/jackson-custom-serialization)
|
||||
- [Getting Started with Custom Deserialization in Jackson](https://www.baeldung.com/jackson-deserialization)
|
||||
- [Serialize Only Fields that meet a Custom Criteria with Jackson](https://www.baeldung.com/jackson-serialize-field-custom-criteria)
|
||||
- [Calling Default Serializer from Custom Serializer in Jackson](https://www.baeldung.com/jackson-call-default-serializer-from-custom-serializer)
|
||||
@@ -1,9 +1,9 @@
|
||||
<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>
|
||||
<artifactId>jackson-2</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<name>jackson-2</name>
|
||||
<artifactId>jackson-custom-conversions</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>jackson-custom-conversions</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
@@ -13,27 +13,25 @@
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- Allow use of LocalDate -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- test scoped -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-joda</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>jackson-2</finalName>
|
||||
<finalName>jackson-custom-conversions</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
@@ -42,10 +40,4 @@
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
|
||||
<!-- testing -->
|
||||
<assertj.version>3.11.0</assertj.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.jackson.entities;
|
||||
package com.baeldung.defaultserializercustomserializer;
|
||||
|
||||
public class File {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.jackson.entities;
|
||||
package com.baeldung.defaultserializercustomserializer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
+1
-2
@@ -1,6 +1,5 @@
|
||||
package com.baeldung.jackson.serialization.custom.serializer;
|
||||
package com.baeldung.defaultserializercustomserializer;
|
||||
|
||||
import com.baeldung.jackson.entities.Folder;
|
||||
import com.fasterxml.jackson.databind.BeanDescription;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializationConfig;
|
||||
+1
-3
@@ -1,9 +1,7 @@
|
||||
package com.baeldung.jackson.serialization.custom.serializer;
|
||||
package com.baeldung.defaultserializercustomserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.baeldung.jackson.entities.File;
|
||||
import com.baeldung.jackson.entities.Folder;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||
+1
-2
@@ -1,8 +1,7 @@
|
||||
package com.baeldung.jackson.serialization.custom.serializer;
|
||||
package com.baeldung.defaultserializercustomserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.baeldung.jackson.entities.Folder;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||
+1
-2
@@ -1,8 +1,7 @@
|
||||
package com.baeldung.jackson.serialization.custom.serializer;
|
||||
package com.baeldung.defaultserializercustomserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.baeldung.jackson.entities.Folder;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
+1
-2
@@ -1,8 +1,7 @@
|
||||
package com.baeldung.jackson.serialization.custom.serializer;
|
||||
package com.baeldung.defaultserializercustomserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.baeldung.jackson.entities.Folder;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
+1
-2
@@ -1,8 +1,7 @@
|
||||
package com.baeldung.jackson.serialization.custom.serializer;
|
||||
package com.baeldung.defaultserializercustomserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.baeldung.jackson.entities.Folder;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.jackson.entities;
|
||||
package com.baeldung.deserialization;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.jackson.dtos;
|
||||
package com.baeldung.deserialization;
|
||||
|
||||
public class Item {
|
||||
public int id;
|
||||
+1
-3
@@ -1,9 +1,7 @@
|
||||
package com.baeldung.jackson.deserialization;
|
||||
package com.baeldung.deserialization;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.baeldung.jackson.dtos.Item;
|
||||
import com.baeldung.jackson.dtos.User;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
+4
-6
@@ -1,9 +1,7 @@
|
||||
package com.baeldung.jackson.deserialization;
|
||||
package com.baeldung.deserialization;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.baeldung.jackson.dtos.ItemWithSerializer;
|
||||
import com.baeldung.jackson.dtos.User;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
@@ -11,7 +9,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||||
import com.fasterxml.jackson.databind.node.IntNode;
|
||||
|
||||
public class ItemDeserializerOnClass extends StdDeserializer<ItemWithSerializer> {
|
||||
public class ItemDeserializerOnClass extends StdDeserializer<ItemWithDeserializer> {
|
||||
|
||||
private static final long serialVersionUID = 5579141241817332594L;
|
||||
|
||||
@@ -27,7 +25,7 @@ public class ItemDeserializerOnClass extends StdDeserializer<ItemWithSerializer>
|
||||
* {"id":1,"itemNr":"theItem","owner":2}
|
||||
*/
|
||||
@Override
|
||||
public ItemWithSerializer deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
||||
public ItemWithDeserializer deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
||||
final JsonNode node = jp.getCodec()
|
||||
.readTree(jp);
|
||||
final int id = (Integer) ((IntNode) node.get("id")).numberValue();
|
||||
@@ -35,7 +33,7 @@ public class ItemDeserializerOnClass extends StdDeserializer<ItemWithSerializer>
|
||||
.asText();
|
||||
final int userId = (Integer) ((IntNode) node.get("owner")).numberValue();
|
||||
|
||||
return new ItemWithSerializer(id, itemName, new User(userId, null));
|
||||
return new ItemWithDeserializer(id, itemName, new User(userId, null));
|
||||
}
|
||||
|
||||
}
|
||||
+3
-8
@@ -1,19 +1,14 @@
|
||||
package com.baeldung.jackson.dtos;
|
||||
|
||||
import com.baeldung.jackson.deserialization.ItemDeserializerOnClass;
|
||||
import com.baeldung.jackson.serialization.ItemSerializerOnClass;
|
||||
package com.baeldung.deserialization;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
@JsonSerialize(using = ItemSerializerOnClass.class)
|
||||
@JsonDeserialize(using = ItemDeserializerOnClass.class)
|
||||
public class ItemWithSerializer {
|
||||
public class ItemWithDeserializer {
|
||||
public final int id;
|
||||
public final String itemName;
|
||||
public final User owner;
|
||||
|
||||
public ItemWithSerializer(final int id, final String itemName, final User owner) {
|
||||
public ItemWithDeserializer(final int id, final String itemName, final User owner) {
|
||||
this.id = id;
|
||||
this.itemName = itemName;
|
||||
this.owner = owner;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.jackson.entities;
|
||||
package com.baeldung.deserialization;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user