outList = gson.fromJson(inputString, listOfAnimals);
+
+ assertEquals(2, outList.size());
+ assertTrue(outList.get(0) instanceof Dog);
+ assertTrue(outList.get(1) instanceof Cow);
+ }
+}
\ No newline at end of file
diff --git a/gson/src/test/java/org/baeldung/gson/advance/RuntimeTypeAdapterFactory.java b/gson/src/test/java/org/baeldung/gson/advance/RuntimeTypeAdapterFactory.java
new file mode 100644
index 0000000000..739dd889c7
--- /dev/null
+++ b/gson/src/test/java/org/baeldung/gson/advance/RuntimeTypeAdapterFactory.java
@@ -0,0 +1,265 @@
+package org.baeldung.gson.advance;
+
+/*
+ * Copyright (C) 2011 Google Inc.
+ *
+ * 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
+ *
+ * http://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.
+ */
+
+import java.io.IOException;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParseException;
+import com.google.gson.JsonPrimitive;
+import com.google.gson.TypeAdapter;
+import com.google.gson.TypeAdapterFactory;
+import com.google.gson.internal.Streams;
+import com.google.gson.reflect.TypeToken;
+import com.google.gson.stream.JsonReader;
+import com.google.gson.stream.JsonWriter;
+
+/**
+ * Adapts values whose runtime type may differ from their declaration type. This
+ * is necessary when a field's type is not the same type that GSON should create
+ * when deserializing that field. For example, consider these types:
+ * {@code
+ * abstract class Shape {
+ * int x;
+ * int y;
+ * }
+ * class Circle extends Shape {
+ * int radius;
+ * }
+ * class Rectangle extends Shape {
+ * int width;
+ * int height;
+ * }
+ * class Diamond extends Shape {
+ * int width;
+ * int height;
+ * }
+ * class Drawing {
+ * Shape bottomShape;
+ * Shape topShape;
+ * }
+ * }
+ * Without additional type information, the serialized JSON is ambiguous. Is
+ * the bottom shape in this drawing a rectangle or a diamond?
{@code
+ * {
+ * "bottomShape": {
+ * "width": 10,
+ * "height": 5,
+ * "x": 0,
+ * "y": 0
+ * },
+ * "topShape": {
+ * "radius": 2,
+ * "x": 4,
+ * "y": 1
+ * }
+ * }}
+ * This class addresses this problem by adding type information to the
+ * serialized JSON and honoring that type information when the JSON is
+ * deserialized: {@code
+ * {
+ * "bottomShape": {
+ * "type": "Diamond",
+ * "width": 10,
+ * "height": 5,
+ * "x": 0,
+ * "y": 0
+ * },
+ * "topShape": {
+ * "type": "Circle",
+ * "radius": 2,
+ * "x": 4,
+ * "y": 1
+ * }
+ * }}
+ * Both the type field name ({@code "type"}) and the type labels ({@code
+ * "Rectangle"}) are configurable.
+ *
+ * Registering Types
+ * Create a {@code RuntimeTypeAdapterFactory} by passing the base type and type field
+ * name to the {@link #of} factory method. If you don't supply an explicit type
+ * field name, {@code "type"} will be used. {@code
+ * RuntimeTypeAdapterFactory shapeAdapterFactory
+ * = RuntimeTypeAdapterFactory.of(Shape.class, "type");
+ * }
+ * Next register all of your subtypes. Every subtype must be explicitly
+ * registered. This protects your application from injection attacks. If you
+ * don't supply an explicit type label, the type's simple name will be used.
+ * {@code
+ * shapeAdapterFactory.registerSubtype(Rectangle.class, "Rectangle");
+ * shapeAdapterFactory.registerSubtype(Circle.class, "Circle");
+ * shapeAdapterFactory.registerSubtype(Diamond.class, "Diamond");
+ * }
+ * Finally, register the type adapter factory in your application's GSON builder:
+ * {@code
+ * Gson gson = new GsonBuilder()
+ * .registerTypeAdapterFactory(shapeAdapterFactory)
+ * .create();
+ * }
+ * Like {@code GsonBuilder}, this API supports chaining: {@code
+ * RuntimeTypeAdapterFactory shapeAdapterFactory = RuntimeTypeAdapterFactory.of(Shape.class)
+ * .registerSubtype(Rectangle.class)
+ * .registerSubtype(Circle.class)
+ * .registerSubtype(Diamond.class);
+ * }
+ */
+public final class RuntimeTypeAdapterFactory implements TypeAdapterFactory {
+ private final Class> baseType;
+ private final String typeFieldName;
+ private final Map> labelToSubtype = new LinkedHashMap>();
+ private final Map, String> subtypeToLabel = new LinkedHashMap, String>();
+ private final boolean maintainType;
+
+ private RuntimeTypeAdapterFactory(Class> baseType, String typeFieldName, boolean maintainType) {
+ if (typeFieldName == null || baseType == null) {
+ throw new NullPointerException();
+ }
+ this.baseType = baseType;
+ this.typeFieldName = typeFieldName;
+ this.maintainType = maintainType;
+ }
+
+ /**
+ * Creates a new runtime type adapter using for {@code baseType} using {@code
+ * typeFieldName} as the type field name. Type field names are case sensitive.
+ * {@code maintainType} flag decide if the type will be stored in pojo or not.
+ */
+ public static RuntimeTypeAdapterFactory of(Class baseType, String typeFieldName, boolean maintainType) {
+ return new RuntimeTypeAdapterFactory(baseType, typeFieldName, maintainType);
+ }
+
+ /**
+ * Creates a new runtime type adapter using for {@code baseType} using {@code
+ * typeFieldName} as the type field name. Type field names are case sensitive.
+ */
+ public static RuntimeTypeAdapterFactory of(Class baseType, String typeFieldName) {
+ return new RuntimeTypeAdapterFactory(baseType, typeFieldName, false);
+ }
+
+ /**
+ * Creates a new runtime type adapter for {@code baseType} using {@code "type"} as
+ * the type field name.
+ */
+ public static RuntimeTypeAdapterFactory of(Class baseType) {
+ return new RuntimeTypeAdapterFactory(baseType, "type", false);
+ }
+
+ /**
+ * Registers {@code type} identified by {@code label}. Labels are case
+ * sensitive.
+ *
+ * @throws IllegalArgumentException if either {@code type} or {@code label}
+ * have already been registered on this type adapter.
+ */
+ public RuntimeTypeAdapterFactory registerSubtype(Class extends T> type, String label) {
+ if (type == null || label == null) {
+ throw new NullPointerException();
+ }
+ if (subtypeToLabel.containsKey(type) || labelToSubtype.containsKey(label)) {
+ throw new IllegalArgumentException("types and labels must be unique");
+ }
+ labelToSubtype.put(label, type);
+ subtypeToLabel.put(type, label);
+ return this;
+ }
+
+ /**
+ * Registers {@code type} identified by its {@link Class#getSimpleName simple
+ * name}. Labels are case sensitive.
+ *
+ * @throws IllegalArgumentException if either {@code type} or its simple name
+ * have already been registered on this type adapter.
+ */
+ public RuntimeTypeAdapterFactory registerSubtype(Class extends T> type) {
+ return registerSubtype(type, type.getSimpleName());
+ }
+
+ public TypeAdapter create(Gson gson, TypeToken type) {
+ if (type.getRawType() != baseType) {
+ return null;
+ }
+
+ final Map> labelToDelegate
+ = new LinkedHashMap>();
+ final Map, TypeAdapter>> subtypeToDelegate
+ = new LinkedHashMap, TypeAdapter>>();
+ for (Map.Entry> entry : labelToSubtype.entrySet()) {
+ TypeAdapter> delegate = gson.getDelegateAdapter(this, TypeToken.get(entry.getValue()));
+ labelToDelegate.put(entry.getKey(), delegate);
+ subtypeToDelegate.put(entry.getValue(), delegate);
+ }
+
+ return new TypeAdapter() {
+ @Override public R read(JsonReader in) throws IOException {
+ JsonElement jsonElement = Streams.parse(in);
+ JsonElement labelJsonElement;
+ if (maintainType) {
+ labelJsonElement = jsonElement.getAsJsonObject().get(typeFieldName);
+ } else {
+ labelJsonElement = jsonElement.getAsJsonObject().remove(typeFieldName);
+ }
+
+ if (labelJsonElement == null) {
+ throw new JsonParseException("cannot deserialize " + baseType
+ + " because it does not define a field named " + typeFieldName);
+ }
+ String label = labelJsonElement.getAsString();
+ @SuppressWarnings("unchecked") // registration requires that subtype extends T
+ TypeAdapter delegate = (TypeAdapter) labelToDelegate.get(label);
+ if (delegate == null) {
+ throw new JsonParseException("cannot deserialize " + baseType + " subtype named "
+ + label + "; did you forget to register a subtype?");
+ }
+ return delegate.fromJsonTree(jsonElement);
+ }
+
+ @Override public void write(JsonWriter out, R value) throws IOException {
+ Class> srcType = value.getClass();
+ String label = subtypeToLabel.get(srcType);
+ @SuppressWarnings("unchecked") // registration requires that subtype extends T
+ TypeAdapter delegate = (TypeAdapter) subtypeToDelegate.get(srcType);
+ if (delegate == null) {
+ throw new JsonParseException("cannot serialize " + srcType.getName()
+ + "; did you forget to register a subtype?");
+ }
+ JsonObject jsonObject = delegate.toJsonTree(value).getAsJsonObject();
+
+ if (maintainType) {
+ Streams.write(jsonObject, out);
+ return;
+ }
+
+ JsonObject clone = new JsonObject();
+
+ if (jsonObject.has(typeFieldName)) {
+ throw new JsonParseException("cannot serialize " + srcType.getName()
+ + " because it already defines a field named " + typeFieldName);
+ }
+ clone.add(typeFieldName, new JsonPrimitive(label));
+
+ for (Map.Entry e : jsonObject.entrySet()) {
+ clone.add(e.getKey(), e.getValue());
+ }
+ Streams.write(clone, out);
+ }
+ }.nullSafe();
+ }
+}
diff --git a/gson/src/test/java/org/baeldung/gson/conversion/JsonObjectConversionsUnitTest.java b/gson/src/test/java/org/baeldung/gson/conversion/JsonObjectConversionsUnitTest.java
new file mode 100644
index 0000000000..847ec1b85d
--- /dev/null
+++ b/gson/src/test/java/org/baeldung/gson/conversion/JsonObjectConversionsUnitTest.java
@@ -0,0 +1,33 @@
+package org.baeldung.gson.conversion;
+
+import com.google.gson.*;
+import org.junit.Assert;
+import org.junit.jupiter.api.Test;
+
+public class JsonObjectConversionsUnitTest {
+
+ @Test
+ void whenUsingJsonParser_thenConvertToJsonObject() throws Exception {
+ // Example 1: Using JsonParser
+ String json = "{ \"name\": \"Baeldung\", \"java\": true }";
+
+ JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();
+
+ Assert.assertTrue(jsonObject.isJsonObject());
+ Assert.assertTrue(jsonObject.get("name").getAsString().equals("Baeldung"));
+ Assert.assertTrue(jsonObject.get("java").getAsBoolean() == true);
+ }
+
+ @Test
+ void whenUsingGsonInstanceFromJson_thenConvertToJsonObject() throws Exception {
+ // Example 2: Using fromJson
+ String json = "{ \"name\": \"Baeldung\", \"java\": true }";
+
+ JsonObject convertedObject = new Gson().fromJson(json, JsonObject.class);
+
+ Assert.assertTrue(convertedObject.isJsonObject());
+ Assert.assertTrue(convertedObject.get("name").getAsString().equals("Baeldung"));
+ Assert.assertTrue(convertedObject.get("java").getAsBoolean() == true);
+ }
+
+}
diff --git a/gson/src/test/java/org/baeldung/gson/deserialization/GsonAlternateUnitTest.java b/gson/src/test/java/org/baeldung/gson/deserialization/GsonAlternateUnitTest.java
new file mode 100644
index 0000000000..f3a5d24e3e
--- /dev/null
+++ b/gson/src/test/java/org/baeldung/gson/deserialization/GsonAlternateUnitTest.java
@@ -0,0 +1,39 @@
+package org.baeldung.gson.deserialization;
+
+import static org.junit.Assert.assertEquals;
+
+import org.baeldung.gson.entities.Weather;
+import org.junit.Test;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+public class GsonAlternateUnitTest {
+
+ @Test
+ public void givenTwoJsonFormats_whenDeserialized_thenWeatherObjectsCreated() throws Exception {
+
+ Gson gson = new GsonBuilder().create();
+
+ Weather weather = gson.fromJson("{" +
+ "\"location\": \"London\"," +
+ "\"temp\": 15," +
+ "\"weather\": \"Cloudy\"" +
+ "}", Weather.class);
+
+ assertEquals("London", weather.getLocation());
+ assertEquals("Cloudy", weather.getOutlook());
+ assertEquals(15, weather.getTemp());
+
+ weather = gson.fromJson("{" +
+ "\"place\": \"Lisbon\"," +
+ "\"temperature\": 35," +
+ "\"outlook\": \"Sunny\"" +
+ "}", Weather.class);
+
+ assertEquals("Lisbon", weather.getLocation());
+ assertEquals("Sunny", weather.getOutlook());
+ assertEquals(35, weather.getTemp());
+
+ }
+}
diff --git a/guava-modules/guava-18/README.md b/guava-modules/guava-18/README.md
index 9924d7c16f..fd5de4170a 100644
--- a/guava-modules/guava-18/README.md
+++ b/guava-modules/guava-18/README.md
@@ -4,9 +4,5 @@
### Relevant Articles:
-- [Guava Collections Cookbook](http://www.baeldung.com/guava-collections)
-- [Guava Ordering Cookbook](http://www.baeldung.com/guava-order)
- [Guava Functional Cookbook](http://www.baeldung.com/guava-functions-predicates)
-- [Hamcrest Collections Cookbook](http://www.baeldung.com/hamcrest-collections-arrays)
-- [Partition a List in Java](http://www.baeldung.com/java-list-split)
- [Guava 18: What’s New?](http://www.baeldung.com/whats-new-in-guava-18)
diff --git a/guava-modules/pom.xml b/guava-modules/pom.xml
new file mode 100644
index 0000000000..fed9e446f7
--- /dev/null
+++ b/guava-modules/pom.xml
@@ -0,0 +1,22 @@
+
+
+ 4.0.0
+ guava-modules
+ guava-modules
+ pom
+
+
+ com.baeldung
+ parent-modules
+ 1.0.0-SNAPSHOT
+ ..
+
+
+
+ guava-18
+ guava-19
+ guava-21
+
+
+
diff --git a/guest/spring-boot-app/src/test/java/com/stackify/test/EmployeeControllerTest.java b/guest/spring-boot-app/src/test/java/com/stackify/test/EmployeeControllerUnitTest.java
similarity index 97%
rename from guest/spring-boot-app/src/test/java/com/stackify/test/EmployeeControllerTest.java
rename to guest/spring-boot-app/src/test/java/com/stackify/test/EmployeeControllerUnitTest.java
index 2711a77ebd..9808546e82 100644
--- a/guest/spring-boot-app/src/test/java/com/stackify/test/EmployeeControllerTest.java
+++ b/guest/spring-boot-app/src/test/java/com/stackify/test/EmployeeControllerUnitTest.java
@@ -21,7 +21,7 @@ import com.stackify.Application;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
@WebAppConfiguration
-public class EmployeeControllerTest {
+public class EmployeeControllerUnitTest {
private static final String CONTENT_TYPE = "application/json;charset=UTF-8";
diff --git a/guice/README.md b/guice/README.md
index d1bd1ff883..77c788c363 100644
--- a/guice/README.md
+++ b/guice/README.md
@@ -2,3 +2,4 @@
### Relevant Articles
- [Guide to Google Guice](http://www.baeldung.com/guice)
+- [Guice vs Spring – Dependency Injection](https://www.baeldung.com/guice-spring-dependency-injection)
diff --git a/helidon/helidon-mp/pom.xml b/helidon/helidon-mp/pom.xml
index 1f39431886..82d52ca2ef 100644
--- a/helidon/helidon-mp/pom.xml
+++ b/helidon/helidon-mp/pom.xml
@@ -15,13 +15,18 @@
io.helidon.microprofile.bundles
helidon-microprofile-1.2
- 0.10.4
+ ${helidon-microprofile.version}
org.glassfish.jersey.media
jersey-media-json-binding
- 2.26
+ ${jersey-media-json-binding.version}
+
+ 0.10.4
+ 2.26
+
+
diff --git a/helidon/helidon-se/pom.xml b/helidon/helidon-se/pom.xml
index 8982bf048e..ae16fa16e4 100644
--- a/helidon/helidon-se/pom.xml
+++ b/helidon/helidon-se/pom.xml
@@ -12,10 +12,6 @@
1.0.0-SNAPSHOT
-
- 0.10.4
-
-
@@ -61,4 +57,8 @@
+
+ 0.10.4
+
+
\ No newline at end of file
diff --git a/httpclient/README.md b/httpclient/README.md
index 93e0f3c9e1..87fb38706d 100644
--- a/httpclient/README.md
+++ b/httpclient/README.md
@@ -12,13 +12,12 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [HttpClient 4 – Cancel / Abort Request](http://www.baeldung.com/httpclient-cancel-request)
- [HttpClient 4 Cookbook](http://www.baeldung.com/httpclient4)
- [Unshorten URLs with HttpClient](http://www.baeldung.com/unshorten-url-httpclient)
-- [HttpClient with SSL](http://www.baeldung.com/httpclient-ssl)
- [HttpClient 4 – Follow Redirects for POST](http://www.baeldung.com/httpclient-redirect-on-http-post)
-- [HttpClient – Set Custom Header](http://www.baeldung.com/httpclient-custom-http-header)
+- [Custom HTTP Header with the HttpClient](http://www.baeldung.com/httpclient-custom-http-header)
- [HttpClient Basic Authentication](http://www.baeldung.com/httpclient-4-basic-authentication)
- [Multipart Upload with HttpClient 4](http://www.baeldung.com/httpclient-multipart-upload)
- [HttpAsyncClient Tutorial](http://www.baeldung.com/httpasyncclient-tutorial)
- [HttpClient 4 Tutorial](http://www.baeldung.com/httpclient-guide)
- [Advanced HttpClient Configuration](http://www.baeldung.com/httpclient-advanced-config)
- [HttpClient 4 – Do Not Follow Redirects](http://www.baeldung.com/httpclient-stop-follow-redirect)
-- [HttpClient 4 – Setting a Custom User-Agent](http://www.baeldung.com/httpclient-user-agent-header)
+- [Custom User-Agent in HttpClient 4](http://www.baeldung.com/httpclient-user-agent-header)
diff --git a/jackson-2/.gitignore b/jackson-2/.gitignore
new file mode 100644
index 0000000000..83c05e60c8
--- /dev/null
+++ b/jackson-2/.gitignore
@@ -0,0 +1,13 @@
+*.class
+
+#folders#
+/target
+/neoDb*
+/data
+/src/main/webapp/WEB-INF/classes
+*/META-INF/*
+
+# Packaged files #
+*.jar
+*.war
+*.ear
\ No newline at end of file
diff --git a/jackson-2/README.md b/jackson-2/README.md
new file mode 100644
index 0000000000..ec147f5fd9
--- /dev/null
+++ b/jackson-2/README.md
@@ -0,0 +1,9 @@
+=========
+
+## Jackson Cookbooks and Examples
+
+###The Course
+The "REST With Spring" Classes: http://bit.ly/restwithspring
+
+### Relevant Articles:
+- [Mapping Multiple JSON Fields to a Single Java Field](https://www.baeldung.com/json-multiple-fields-single-java-field)
diff --git a/jackson-2/pom.xml b/jackson-2/pom.xml
new file mode 100644
index 0000000000..ddbcb81dcc
--- /dev/null
+++ b/jackson-2/pom.xml
@@ -0,0 +1,52 @@
+
+ 4.0.0
+ jackson-2
+ 0.1-SNAPSHOT
+ jackson-2
+
+
+ com.baeldung
+ parent-java
+ 0.0.1-SNAPSHOT
+ ../parent-java
+
+
+
+
+
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ ${jackson.version}
+
+
+
+
+
+
+ org.assertj
+ assertj-core
+ ${assertj.version}
+ test
+
+
+
+
+ jackson-2
+
+
+ src/main/resources
+ true
+
+
+
+
+
+
+
+ 3.11.0
+
+
+
diff --git a/jackson-2/src/main/java/com/baeldung/jackson/entities/Weather.java b/jackson-2/src/main/java/com/baeldung/jackson/entities/Weather.java
new file mode 100644
index 0000000000..4a8cea052f
--- /dev/null
+++ b/jackson-2/src/main/java/com/baeldung/jackson/entities/Weather.java
@@ -0,0 +1,44 @@
+package com.baeldung.jackson.entities;
+
+import com.fasterxml.jackson.annotation.JsonAlias;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class Weather {
+
+ @JsonProperty("location")
+ @JsonAlias("place")
+ private String location;
+
+ @JsonProperty("temp")
+ @JsonAlias("temperature")
+ private int temp;
+
+ @JsonProperty("outlook")
+ @JsonAlias("weather")
+ private String outlook;
+
+ public String getLocation() {
+ return location;
+ }
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ public int getTemp() {
+ return temp;
+ }
+
+ public void setTemp(int temp) {
+ this.temp = temp;
+ }
+
+ public String getOutlook() {
+ return outlook;
+ }
+
+ public void setOutlook(String outlook) {
+ this.outlook = outlook;
+ }
+
+}
diff --git a/jackson-2/src/main/resources/logback.xml b/jackson-2/src/main/resources/logback.xml
new file mode 100644
index 0000000000..7d900d8ea8
--- /dev/null
+++ b/jackson-2/src/main/resources/logback.xml
@@ -0,0 +1,13 @@
+
+
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/jackson-2/src/test/java/com/baeldung/jackson/deserialization/jsonalias/JsonAliasUnitTest.java b/jackson-2/src/test/java/com/baeldung/jackson/deserialization/jsonalias/JsonAliasUnitTest.java
new file mode 100644
index 0000000000..b5940a7bd7
--- /dev/null
+++ b/jackson-2/src/test/java/com/baeldung/jackson/deserialization/jsonalias/JsonAliasUnitTest.java
@@ -0,0 +1,38 @@
+package com.baeldung.jackson.deserialization.jsonalias;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import com.baeldung.jackson.entities.Weather;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class JsonAliasUnitTest {
+
+ @Test
+ public void givenTwoJsonFormats_whenDeserialized_thenWeatherObjectsCreated() throws Exception {
+
+ ObjectMapper mapper = new ObjectMapper();
+
+ Weather weather = mapper.readValue("{" +
+ "\"location\": \"London\"," +
+ "\"temp\": 15," +
+ "\"weather\": \"Cloudy\"" +
+ "}", Weather.class);
+
+ assertEquals("London", weather.getLocation());
+ assertEquals("Cloudy", weather.getOutlook());
+ assertEquals(15, weather.getTemp());
+
+ weather = mapper.readValue("{" +
+ "\"place\": \"Lisbon\"," +
+ "\"temperature\": 35," +
+ "\"outlook\": \"Sunny\"" +
+ "}", Weather.class);
+
+ assertEquals("Lisbon", weather.getLocation());
+ assertEquals("Sunny", weather.getOutlook());
+ assertEquals(35, weather.getTemp());
+
+ }
+}
diff --git a/jackson/README.md b/jackson/README.md
index e201a06727..e9cf6f212c 100644
--- a/jackson/README.md
+++ b/jackson/README.md
@@ -10,14 +10,14 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Jackson – Unmarshall to Collection/Array](http://www.baeldung.com/jackson-collection-array)
- [Jackson Unmarshalling json with Unknown Properties](http://www.baeldung.com/jackson-deserialize-json-unknown-properties)
- [Jackson – Custom Serializer](http://www.baeldung.com/jackson-custom-serialization)
-- [Jackson – Custom Deserializer](http://www.baeldung.com/jackson-deserialization)
+- [Getting Started with Custom Deserialization in Jackson](http://www.baeldung.com/jackson-deserialization)
- [Jackson Exceptions – Problems and Solutions](http://www.baeldung.com/jackson-exception)
- [Jackson Date](http://www.baeldung.com/jackson-serialize-dates)
- [Jackson – Bidirectional Relationships](http://www.baeldung.com/jackson-bidirectional-relationships-and-infinite-recursion)
- [Jackson JSON Tutorial](http://www.baeldung.com/jackson)
- [Jackson – Working with Maps and nulls](http://www.baeldung.com/jackson-map-null-values-or-null-key)
- [Jackson – Decide What Fields Get Serialized/Deserializaed](http://www.baeldung.com/jackson-field-serializable-deserializable-or-not)
-- [A Guide to Jackson Annotations](http://www.baeldung.com/jackson-annotations)
+- [Jackson Annotation Examples](http://www.baeldung.com/jackson-annotations)
- [Working with Tree Model Nodes in Jackson](http://www.baeldung.com/jackson-json-node-tree-model)
- [Jackson vs Gson](http://www.baeldung.com/jackson-vs-gson)
- [Intro to the Jackson ObjectMapper](http://www.baeldung.com/jackson-object-mapper-tutorial)
@@ -25,7 +25,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [More Jackson Annotations](http://www.baeldung.com/jackson-advanced-annotations)
- [Inheritance with Jackson](http://www.baeldung.com/jackson-inheritance)
- [Guide to @JsonFormat in Jackson](http://www.baeldung.com/jackson-jsonformat)
-- [A Guide to Optional with Jackson](http://www.baeldung.com/jackson-optional)
+- [Using Optional with Jackson](http://www.baeldung.com/jackson-optional)
- [Map Serialization and Deserialization with Jackson](http://www.baeldung.com/jackson-map)
- [Jackson Streaming API](http://www.baeldung.com/jackson-streaming-api)
- [Jackson – JsonMappingException (No serializer found for class)](http://www.baeldung.com/jackson-jsonmappingexception)
@@ -38,3 +38,5 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Mapping Nested Values with Jackson](http://www.baeldung.com/jackson-nested-values)
- [Convert XML to JSON Using Jackson](https://www.baeldung.com/jackson-convert-xml-json)
- [Deserialize Immutable Objects with Jackson](https://www.baeldung.com/jackson-deserialize-immutable-objects)
+- [Mapping a Dynamic JSON Object with Jackson](https://www.baeldung.com/jackson-mapping-dynamic-object)
+
diff --git a/jackson/pom.xml b/jackson/pom.xml
index e941ababc5..948248d255 100644
--- a/jackson/pom.xml
+++ b/jackson/pom.xml
@@ -117,8 +117,6 @@
-
- 2.9.7
3.8
2.10
diff --git a/jackson/src/main/java/com/baeldung/jackson/deserialization/jacksoninject/Author.java b/jackson/src/main/java/com/baeldung/jackson/deserialization/jacksoninject/Author.java
deleted file mode 100644
index db8b594509..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/deserialization/jacksoninject/Author.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.baeldung.jackson.deserialization.jacksoninject;
-
-import com.baeldung.jackson.domain.Item;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class Author extends Person {
-
- List- items = new ArrayList<>();
-
- public Author() {
- }
-
- public Author(String firstName, String lastName) {
- super(firstName, lastName);
- }
-
- public List
- getItems() {
- return items;
- }
-
- public void setItems(List
- items) {
- this.items = items;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/deserialization/jsonanysetter/Inventory.java b/jackson/src/main/java/com/baeldung/jackson/deserialization/jsonanysetter/Inventory.java
index c4daf68bd6..d9748e2997 100644
--- a/jackson/src/main/java/com/baeldung/jackson/deserialization/jsonanysetter/Inventory.java
+++ b/jackson/src/main/java/com/baeldung/jackson/deserialization/jsonanysetter/Inventory.java
@@ -1,24 +1,14 @@
package com.baeldung.jackson.deserialization.jsonanysetter;
-import com.baeldung.jackson.domain.Author;
-import com.baeldung.jackson.domain.Item;
-import com.fasterxml.jackson.annotation.JsonAnySetter;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-
import java.util.HashMap;
import java.util.Map;
+import com.fasterxml.jackson.annotation.JsonAnySetter;
+
public class Inventory {
- private Map
stock = new HashMap<>();
-
private Map countryDeliveryCost = new HashMap<>();
- @JsonIgnore
- public Map getStock() {
- return stock;
- }
-
public Map getCountryDeliveryCost() {
return countryDeliveryCost;
}
diff --git a/jackson/src/main/java/com/baeldung/jackson/deserialization/jsoncreator/Author.java b/jackson/src/main/java/com/baeldung/jackson/deserialization/jsoncreator/Author.java
deleted file mode 100644
index d48c95b255..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/deserialization/jsoncreator/Author.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.baeldung.jackson.deserialization.jsoncreator;
-
-import com.baeldung.jackson.domain.Person;
-import com.baeldung.jackson.domain.Item;
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class Author extends Person {
-
- List- items = new ArrayList<>();
-
- @JsonCreator
- public Author(@JsonProperty("christianName") String firstName, @JsonProperty("surname") String lastName) {
- super(firstName, lastName);
- }
-
- public List
- getItems() {
- return items;
- }
-
- public void setItems(List
- items) {
- this.items = items;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/deserialization/jsondeserialize/Author.java b/jackson/src/main/java/com/baeldung/jackson/deserialization/jsondeserialize/Author.java
deleted file mode 100644
index 62e108facb..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/deserialization/jsondeserialize/Author.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.baeldung.jackson.deserialization.jsondeserialize;
-
-import com.baeldung.jackson.domain.Item;
-import com.baeldung.jackson.domain.Person;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class Author extends Person {
-
- List
- items = new ArrayList<>();
-
- public Author(String firstName, String lastName) {
- super(firstName, lastName);
- }
-
- public List
- getItems() {
- return items;
- }
-
- public void setItems(List
- items) {
- this.items = items;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/deserialization/jsondeserialize/Book.java b/jackson/src/main/java/com/baeldung/jackson/deserialization/jsondeserialize/Book.java
index dc0d0ee623..1e411da64e 100644
--- a/jackson/src/main/java/com/baeldung/jackson/deserialization/jsondeserialize/Book.java
+++ b/jackson/src/main/java/com/baeldung/jackson/deserialization/jsondeserialize/Book.java
@@ -1,12 +1,16 @@
package com.baeldung.jackson.deserialization.jsondeserialize;
-import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
-
import java.math.BigDecimal;
import java.util.Date;
+import java.util.UUID;
-public class Book extends Item {
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+public class Book {
+
+ private UUID id;
+ private String title;
+ private float price;
private String ISBN;
@JsonDeserialize(using = CustomDateDeserializer.class)
@@ -16,8 +20,9 @@ public class Book extends Item {
public Book() {
}
- public Book(String title, Author author) {
- super(title, author);
+ public Book(String title) {
+ this.id = UUID.randomUUID();
+ this.title = title;
}
public String getISBN() {
@@ -43,4 +48,28 @@ public class Book extends Item {
public void setPages(BigDecimal pages) {
this.pages = pages;
}
+
+ public UUID getId() {
+ return id;
+ }
+
+ public void setId(UUID id) {
+ this.id = id;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public float getPrice() {
+ return price;
+ }
+
+ public void setPrice(float price) {
+ this.price = price;
+ }
}
diff --git a/jackson/src/main/java/com/baeldung/jackson/deserialization/jsondeserialize/Item.java b/jackson/src/main/java/com/baeldung/jackson/deserialization/jsondeserialize/Item.java
deleted file mode 100644
index fc27a586ac..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/deserialization/jsondeserialize/Item.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package com.baeldung.jackson.deserialization.jsondeserialize;
-
-import com.baeldung.jackson.domain.Person;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Item {
-
- private UUID id;
- private String title;
- private List
authors = new ArrayList<>();
- private float price;
-
- public Item() {
- }
-
- public Item(String title, Author author) {
- this.id = UUID.randomUUID();
- this.title = title;
- this.authors.add(author);
- }
-
- public UUID getId() {
- return id;
- }
-
- public void setId(UUID id) {
- this.id = id;
- }
-
- public String getTitle() {
- return title;
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- public List getAuthors() {
- return authors;
- }
-
- public void setAuthors(List authors) {
- this.authors = authors;
- }
-
- public float getPrice() {
- return price;
- }
-
- public void setPrice(float price) {
- this.price = price;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/deserialization/jsonsetter/Author.java b/jackson/src/main/java/com/baeldung/jackson/deserialization/jsonsetter/Author.java
deleted file mode 100644
index 3f9ae70a88..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/deserialization/jsonsetter/Author.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.baeldung.jackson.deserialization.jsonsetter;
-
-import com.baeldung.jackson.domain.Item;
-import com.baeldung.jackson.domain.Person;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonSetter;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Author extends Person {
-
- private List- items = new ArrayList<>();
-
- public Author() {
- }
-
- public Author(String firstName, String lastName) {
- super(firstName, lastName);
- }
-
- @JsonIgnore
- public List
- getItems() {
- return items;
- }
-
- @JsonSetter("publications")
- public void setItems(List
- items) {
- this.items = items;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/domain/Author.java b/jackson/src/main/java/com/baeldung/jackson/domain/Author.java
deleted file mode 100644
index 9000c00f21..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/domain/Author.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.baeldung.jackson.domain;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Author extends Person {
-
- private List
- items = new ArrayList<>();
-
- public Author(String firstName, String lastName) {
- super(firstName, lastName);
- }
-
- public List
- getItems() {
- return items;
- }
-
- public void setItems(List
- items) {
- this.items = items;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/domain/Book.java b/jackson/src/main/java/com/baeldung/jackson/domain/Book.java
deleted file mode 100644
index a5963e33ba..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/domain/Book.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package com.baeldung.jackson.domain;
-
-import java.math.BigDecimal;
-import java.util.Date;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Book extends Item {
-
- private String ISBN;
- private Date published;
- private BigDecimal pages;
-
- public Book() {
- }
-
- public Book(String title, Author author) {
- super(title, author);
- }
-
- public String getISBN() {
- return ISBN;
- }
-
- public void setISBN(String ISBN) {
- this.ISBN = ISBN;
- }
-
- public Date getPublished() {
- return published;
- }
-
- public void setPublished(Date published) {
- this.published = published;
- }
-
- public BigDecimal getPages() {
- return pages;
- }
-
- public void setPages(BigDecimal pages) {
- this.pages = pages;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/domain/Course.java b/jackson/src/main/java/com/baeldung/jackson/domain/Course.java
deleted file mode 100644
index 672b0bc250..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/domain/Course.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package com.baeldung.jackson.domain;
-
-import java.util.List;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Course extends Item {
-
- public enum Medium {
- CLASSROOM, ONLINE
- }
-
- public enum Level {
- BEGINNER("Beginner", 1), INTERMEDIATE("Intermediate", 2), ADVANCED("Advanced", 3);
-
- private String name;
- private int number;
-
- Level(String name, int number) {
- this.name = name;
- this.number = number;
- }
-
- public String getName() {
- return name;
- }
- }
-
- private float duration;
- private Medium medium;
- private Level level;
- private List
prerequisite;
-
- public Course(String title, Author author) {
- super(title, author);
- }
-
- public float getDuration() {
- return duration;
- }
-
- public void setDuration(float duration) {
- this.duration = duration;
- }
-
- public Medium getMedium() {
- return medium;
- }
-
- public void setMedium(Medium medium) {
- this.medium = medium;
- }
-
- public Level getLevel() {
- return level;
- }
-
- public void setLevel(Level level) {
- this.level = level;
- }
-
- public List getPrerequisite() {
- return prerequisite;
- }
-
- public void setPrerequisite(List prerequisite) {
- this.prerequisite = prerequisite;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/domain/Customer.java b/jackson/src/main/java/com/baeldung/jackson/domain/Customer.java
deleted file mode 100644
index 1e03ff9a13..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/domain/Customer.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.baeldung.jackson.domain;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Customer extends Person {
-
- private String configuration;
-
- public Customer(String firstName, String lastName) {
- super(firstName, lastName);
- }
-
- public String getConfiguration() {
- return configuration;
- }
-
- public void setConfiguration(String configuration) {
- this.configuration = configuration;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/domain/Inventory.java b/jackson/src/main/java/com/baeldung/jackson/domain/Inventory.java
deleted file mode 100644
index 41b7dc51da..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/domain/Inventory.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package com.baeldung.jackson.domain;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Inventory {
-
- private Map stock;
-
- private Map countryDeliveryCost = new HashMap<>();
-
- public Map getStock() {
- return stock;
- }
-
- public void setStock(Map stock) {
- this.stock = stock;
- }
-
- public Map getCountryDeliveryCost() {
- return countryDeliveryCost;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/domain/Item.java b/jackson/src/main/java/com/baeldung/jackson/domain/Item.java
deleted file mode 100644
index d9d1350a8e..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/domain/Item.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package com.baeldung.jackson.domain;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Item {
-
- private UUID id;
- private String title;
- private List authors = new ArrayList<>();
- private float price;
-
- public Item() {
- }
-
- public Item(String title, Author author) {
- this.id = UUID.randomUUID();
- this.title = title;
- this.authors.add(author);
- }
-
- public UUID getId() {
- return id;
- }
-
- public void setId(UUID id) {
- this.id = id;
- }
-
- public String getTitle() {
- return title;
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- public List getAuthors() {
- return authors;
- }
-
- public void setAuthors(List authors) {
- this.authors = authors;
- }
-
- public float getPrice() {
- return price;
- }
-
- public void setPrice(float price) {
- this.price = price;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/domain/Order.java b/jackson/src/main/java/com/baeldung/jackson/domain/Order.java
deleted file mode 100644
index 91f87f74df..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/domain/Order.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package com.baeldung.jackson.domain;
-
-import java.util.UUID;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Order {
-
- private UUID id;
- private Type type;
- private int internalAudit;
-
- public static class Type {
- public long id;
- public String name;
- }
-
- public Order() {
- this.id = UUID.randomUUID();
- }
-
- public Order(Type type) {
- this();
- this.type = type;
- }
-
- public Order(int internalAudit) {
- this();
- this.type = new Type();
- this.type.id = 20;
- this.type.name = "Order";
- this.internalAudit = internalAudit;
- }
-
- public UUID getId() {
- return id;
- }
-
- public Type getType() {
- return type;
- }
-
- public void setType(Type type) {
- this.type = type;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/domain/Person.java b/jackson/src/main/java/com/baeldung/jackson/domain/Person.java
index 785efff755..f11ba41113 100644
--- a/jackson/src/main/java/com/baeldung/jackson/domain/Person.java
+++ b/jackson/src/main/java/com/baeldung/jackson/domain/Person.java
@@ -1,24 +1,12 @@
package com.baeldung.jackson.domain;
-import java.util.UUID;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
public class Person {
- private UUID id;
private String firstName;
private String lastName;
-
- public Person() {
- }
-
+
public Person(String firstName, String lastName) {
- this.id = UUID.randomUUID();
+ super();
this.firstName = firstName;
this.lastName = lastName;
}
@@ -38,8 +26,5 @@ public class Person {
public void setLastName(String lastName) {
this.lastName = lastName;
}
-
- public UUID getId() {
- return id;
- }
}
+
diff --git a/jackson/src/main/java/com/baeldung/jackson/inclusion/jsonautodetect/Order.java b/jackson/src/main/java/com/baeldung/jackson/inclusion/jsonautodetect/Order.java
deleted file mode 100644
index f2ff5eeb08..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/inclusion/jsonautodetect/Order.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package com.baeldung.jackson.inclusion.jsonautodetect;
-
-import com.fasterxml.jackson.annotation.JsonAutoDetect;
-import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
-
-import java.util.UUID;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-@JsonAutoDetect(fieldVisibility = Visibility.ANY)
-public class Order {
-
- private UUID id;
- private Type type;
- private int internalAudit;
-
- public static class Type {
- public long id;
- public String name;
- }
-
- public Order() {
- this.id = UUID.randomUUID();
- }
-
- public Order(Type type) {
- this();
- this.type = type;
- }
-
- public Order(int internalAudit) {
- this();
- this.type = new Type();
- this.type.id = 20;
- this.type.name = "Order";
- this.internalAudit = internalAudit;
- }
-
- public UUID getId() {
- return id;
- }
-
- public Type getType() {
- return type;
- }
-
- public void setType(Type type) {
- this.type = type;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/inclusion/jsonignore/Author.java b/jackson/src/main/java/com/baeldung/jackson/inclusion/jsonignore/Author.java
deleted file mode 100644
index a7801493bf..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/inclusion/jsonignore/Author.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package com.baeldung.jackson.inclusion.jsonignore;
-
-import com.baeldung.jackson.domain.Item;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Author extends Person {
-
- private List- items = new ArrayList<>();
-
- public Author(String firstName, String lastName) {
- super(firstName, lastName);
- }
-
- public List
- getItems() {
- return items;
- }
-
- public void setItems(List
- items) {
- this.items = items;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/inclusion/jsonignore/Person.java b/jackson/src/main/java/com/baeldung/jackson/inclusion/jsonignore/Person.java
deleted file mode 100644
index 0037d83148..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/inclusion/jsonignore/Person.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package com.baeldung.jackson.inclusion.jsonignore;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-
-import java.util.UUID;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Person {
-
- @JsonIgnore
- private UUID id;
- private String firstName;
- private String lastName;
-
- public Person() {
- }
-
- public Person(String firstName, String lastName) {
- this.id = UUID.randomUUID();
- this.firstName = firstName;
- this.lastName = lastName;
- }
-
- public String getFirstName() {
- return firstName;
- }
-
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
-
- public String getLastName() {
- return lastName;
- }
-
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
-
- public UUID getId() {
- return id;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/inclusion/jsonignoreproperties/Course.java b/jackson/src/main/java/com/baeldung/jackson/inclusion/jsonignoreproperties/Course.java
deleted file mode 100644
index 70b4dd9842..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/inclusion/jsonignoreproperties/Course.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package com.baeldung.jackson.inclusion.jsonignoreproperties;
-
-import com.baeldung.jackson.domain.Author;
-import com.baeldung.jackson.domain.Item;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-
-import java.util.List;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-@JsonIgnoreProperties({ "medium" })
-public class Course extends Item {
-
- public enum Medium {
- CLASSROOM, ONLINE
- }
-
- public enum Level {
- BEGINNER("Beginner", 1), INTERMEDIATE("Intermediate", 2), ADVANCED("Advanced", 3);
-
- private String name;
- private int number;
-
- Level(String name, int number) {
- this.name = name;
- this.number = number;
- }
-
- public String getName() {
- return name;
- }
- }
-
- private float duration;
- private Medium medium;
- private Level level;
- private List
prerequisite;
-
- public Course(String title, Author author) {
- super(title, author);
- }
-
- public float getDuration() {
- return duration;
- }
-
- public void setDuration(float duration) {
- this.duration = duration;
- }
-
- public Medium getMedium() {
- return medium;
- }
-
- public void setMedium(Medium medium) {
- this.medium = medium;
- }
-
- public Level getLevel() {
- return level;
- }
-
- public void setLevel(Level level) {
- this.level = level;
- }
-
- public List getPrerequisite() {
- return prerequisite;
- }
-
- public void setPrerequisite(List prerequisite) {
- this.prerequisite = prerequisite;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/inclusion/jsonignoretype/Order.java b/jackson/src/main/java/com/baeldung/jackson/inclusion/jsonignoretype/Order.java
deleted file mode 100644
index 0d8867933f..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/inclusion/jsonignoretype/Order.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package com.baeldung.jackson.inclusion.jsonignoretype;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreType;
-
-import java.util.UUID;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Order {
-
- private UUID id;
- private Type type;
-
- @JsonIgnoreType
- public static class Type {
- public long id;
- public String name;
- }
-
- public Order() {
- this.id = UUID.randomUUID();
- }
-
- public Order(Type type) {
- this();
- this.type = type;
- }
-
- public UUID getId() {
- return id;
- }
-
- public Type getType() {
- return type;
- }
-
- public void setType(Type type) {
- this.type = type;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/inclusion/jsoninclude/Author.java b/jackson/src/main/java/com/baeldung/jackson/inclusion/jsoninclude/Author.java
deleted file mode 100644
index 30cb2735c2..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/inclusion/jsoninclude/Author.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.baeldung.jackson.inclusion.jsoninclude;
-
-import com.baeldung.jackson.domain.Person;
-import com.baeldung.jackson.domain.Item;
-import com.fasterxml.jackson.annotation.JsonInclude;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-@JsonInclude(NON_NULL)
-public class Author extends Person {
-
- private List- items = new ArrayList<>();
-
- public Author(String firstName, String lastName) {
- super(firstName, lastName);
- }
-
- public List
- getItems() {
- return items;
- }
-
- public void setItems(List
- items) {
- this.items = items;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/miscellaneous/custom/Course.java b/jackson/src/main/java/com/baeldung/jackson/miscellaneous/custom/Course.java
deleted file mode 100644
index a44492b9f7..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/miscellaneous/custom/Course.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package com.baeldung.jackson.miscellaneous.custom;
-
-import com.baeldung.jackson.domain.Author;
-
-import java.util.List;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-@CustomCourseAnnotation
-public class Course extends Item {
-
- public enum Medium {
- CLASSROOM, ONLINE
- }
-
- public enum Level {
- BEGINNER("Beginner", 1), INTERMEDIATE("Intermediate", 2), ADVANCED("Advanced", 3);
-
- private String name;
- private int number;
-
- Level(String name, int number) {
- this.name = name;
- this.number = number;
- }
-
- public String getName() {
- return name;
- }
- }
-
- private float duration;
- private Medium medium;
- private Level level;
- private List
prerequisite;
-
- public Course(String title, Author author) {
- super(title, author);
- }
-
- public float getDuration() {
- return duration;
- }
-
- public void setDuration(float duration) {
- this.duration = duration;
- }
-
- public Medium getMedium() {
- return medium;
- }
-
- public void setMedium(Medium medium) {
- this.medium = medium;
- }
-
- public Level getLevel() {
- return level;
- }
-
- public void setLevel(Level level) {
- this.level = level;
- }
-
- public List getPrerequisite() {
- return prerequisite;
- }
-
- public void setPrerequisite(List prerequisite) {
- this.prerequisite = prerequisite;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/miscellaneous/custom/CustomCourseAnnotation.java b/jackson/src/main/java/com/baeldung/jackson/miscellaneous/custom/CustomCourseAnnotation.java
deleted file mode 100644
index d7f72ca6ec..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/miscellaneous/custom/CustomCourseAnnotation.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.baeldung.jackson.miscellaneous.custom;
-
-import com.fasterxml.jackson.annotation.*;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-@Retention(RetentionPolicy.RUNTIME)
-@JacksonAnnotationsInside
-@JsonInclude(JsonInclude.Include.NON_NULL)
-@JsonPropertyOrder({ "title", "price", "id", "duration", "authors", "level" })
-@JsonIgnoreProperties({ "prerequisite" })
-public @interface CustomCourseAnnotation {
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/miscellaneous/custom/Item.java b/jackson/src/main/java/com/baeldung/jackson/miscellaneous/custom/Item.java
deleted file mode 100644
index 6625283dec..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/miscellaneous/custom/Item.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package com.baeldung.jackson.miscellaneous.custom;
-
-import com.baeldung.jackson.domain.Author;
-import com.baeldung.jackson.domain.Person;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Item {
-
- private UUID id;
- private String title;
- private List authors = new ArrayList<>();
- private float price;
-
- public Item() {
- }
-
- public Item(String title, Author author) {
- this.id = UUID.randomUUID();
- this.title = title;
- this.authors.add(author);
- }
-
- public UUID getId() {
- return id;
- }
-
- public void setId(UUID id) {
- this.id = id;
- }
-
- public String getTitle() {
- return title;
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- public List getAuthors() {
- return authors;
- }
-
- public void setAuthors(List authors) {
- this.authors = authors;
- }
-
- public float getPrice() {
- return price;
- }
-
- public void setPrice(float price) {
- this.price = price;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/miscellaneous/disable/Author.java b/jackson/src/main/java/com/baeldung/jackson/miscellaneous/disable/Author.java
deleted file mode 100644
index 0638e32925..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/miscellaneous/disable/Author.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.baeldung.jackson.miscellaneous.disable;
-
-import com.baeldung.jackson.domain.Item;
-import com.baeldung.jackson.domain.Person;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.JsonPropertyOrder;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-@JsonInclude(JsonInclude.Include.NON_NULL)
-@JsonPropertyOrder({ "lastName", "items", "firstName", "id" })
-public class Author extends Person {
-
- @JsonIgnore
- private List- items = new ArrayList<>();
-
- public Author(String firstName, String lastName) {
- super(firstName, lastName);
- }
-
- public List
- getItems() {
- return items;
- }
-
- public void setItems(List
- items) {
- this.items = items;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/miscellaneous/mixin/Author.java b/jackson/src/main/java/com/baeldung/jackson/miscellaneous/mixin/Author.java
deleted file mode 100644
index 26e3e4b647..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/miscellaneous/mixin/Author.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.baeldung.jackson.miscellaneous.mixin;
-
-import com.baeldung.jackson.domain.Item;
-import com.baeldung.jackson.domain.Person;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Author extends Person {
-
- private List
- items = new ArrayList<>();
-
- public Author(String firstName, String lastName) {
- super(firstName, lastName);
- }
-
- public List
- getItems() {
- return items;
- }
-
- public void setItems(List
- items) {
- this.items = items;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/miscellaneous/mixin/IgnoreListMixIn.java b/jackson/src/main/java/com/baeldung/jackson/miscellaneous/mixin/IgnoreListMixIn.java
deleted file mode 100644
index 418c09c251..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/miscellaneous/mixin/IgnoreListMixIn.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.baeldung.jackson.miscellaneous.mixin;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreType;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-@JsonIgnoreType
-public class IgnoreListMixIn {
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/polymorphism/Order.java b/jackson/src/main/java/com/baeldung/jackson/polymorphism/Order.java
deleted file mode 100644
index 1813148b2b..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/polymorphism/Order.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package com.baeldung.jackson.polymorphism;
-
-import com.fasterxml.jackson.annotation.JsonSubTypes;
-import com.fasterxml.jackson.annotation.JsonTypeInfo;
-import com.fasterxml.jackson.annotation.JsonTypeName;
-
-import java.util.UUID;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Order {
-
- private UUID id;
- private Type type;
- private int internalAudit;
-
- @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "ordertype")
- @JsonSubTypes({ @JsonSubTypes.Type(value = InternalType.class, name = "internal") })
- public static class Type {
- public long id;
- public String name;
- }
-
- @JsonTypeName("internal")
- public static class InternalType extends Type {
- public long id;
- public String name;
- }
-
- public Order() {
- this.id = UUID.randomUUID();
- }
-
- public Order(Type type) {
- this();
- this.type = type;
- }
-
- public Order(int internalAudit) {
- this();
- this.type = new Type();
- this.type.id = 20;
- this.type.name = "Order";
- this.internalAudit = internalAudit;
- }
-
- public UUID getId() {
- return id;
- }
-
- public Type getType() {
- return type;
- }
-
- public void setType(Type type) {
- this.type = type;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/serialization/jsonanygetter/Inventory.java b/jackson/src/main/java/com/baeldung/jackson/serialization/jsonanygetter/Inventory.java
deleted file mode 100644
index 52f586d93b..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/serialization/jsonanygetter/Inventory.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.baeldung.jackson.serialization.jsonanygetter;
-
-import com.baeldung.jackson.domain.Author;
-import com.baeldung.jackson.domain.Item;
-import com.fasterxml.jackson.annotation.JsonAnyGetter;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Inventory {
-
- private String location;
-
- private Map
stock = new HashMap<>();
-
- private Map countryDeliveryCost = new HashMap<>();
-
- public String getLocation() {
- return location;
- }
-
- public void setLocation(String location) {
- this.location = location;
- }
-
- @JsonIgnore
- public Map getStock() {
- return stock;
- }
-
- @JsonAnyGetter
- public Map getCountryDeliveryCost() {
- return countryDeliveryCost;
- }
-
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/serialization/jsongetter/Author.java b/jackson/src/main/java/com/baeldung/jackson/serialization/jsongetter/Author.java
deleted file mode 100644
index 8d89fefce7..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/serialization/jsongetter/Author.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package com.baeldung.jackson.serialization.jsongetter;
-
-import com.baeldung.jackson.domain.Item;
-import com.baeldung.jackson.domain.Person;
-import com.fasterxml.jackson.annotation.JsonGetter;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Author extends Person {
-
- List- items = new ArrayList<>();
-
- public Author(String firstName, String lastName) {
- super(firstName, lastName);
- }
-
- @JsonGetter("publications")
- public List
- getItems() {
- return items;
- }
-
- public void setItems(List
- items) {
- this.items = items;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/serialization/jsonpropertyorder/Author.java b/jackson/src/main/java/com/baeldung/jackson/serialization/jsonpropertyorder/Author.java
deleted file mode 100644
index dadf893cf9..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/serialization/jsonpropertyorder/Author.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.baeldung.jackson.serialization.jsonpropertyorder;
-
-import com.baeldung.jackson.domain.Item;
-import com.fasterxml.jackson.annotation.JsonPropertyOrder;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-@JsonPropertyOrder({ "items", "firstName", "lastName", "id" })
-public class Author extends Person {
-
- List
- items = new ArrayList<>();
-
- public Author(String firstName, String lastName) {
- super(firstName, lastName);
- }
-
- public List
- getItems() {
- return items;
- }
-
- public void setItems(List
- items) {
- this.items = items;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/serialization/jsonpropertyorder/Person.java b/jackson/src/main/java/com/baeldung/jackson/serialization/jsonpropertyorder/Person.java
deleted file mode 100644
index 519e48aada..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/serialization/jsonpropertyorder/Person.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package com.baeldung.jackson.serialization.jsonpropertyorder;
-
-import java.util.UUID;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Person {
-
- private UUID id;
- private String firstName;
- private String lastName;
-
- public Person(String firstName, String lastName) {
- this.id = UUID.randomUUID();
- this.firstName = firstName;
- this.lastName = lastName;
- }
-
- public String getFirstName() {
- return firstName;
- }
-
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
-
- public String getLastName() {
- return lastName;
- }
-
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
-
- public UUID getId() {
- return id;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/serialization/jsonrawvalue/Customer.java b/jackson/src/main/java/com/baeldung/jackson/serialization/jsonrawvalue/Customer.java
deleted file mode 100644
index f19c5314d2..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/serialization/jsonrawvalue/Customer.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.baeldung.jackson.serialization.jsonrawvalue;
-
-import com.baeldung.jackson.domain.Person;
-import com.fasterxml.jackson.annotation.JsonRawValue;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Customer extends Person {
-
- @JsonRawValue
- private String configuration;
-
- public Customer(String firstName, String lastName) {
- super(firstName, lastName);
- }
-
- public String getConfiguration() {
- return configuration;
- }
-
- public void setConfiguration(String configuration) {
- this.configuration = configuration;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/serialization/jsonrootname/Author.java b/jackson/src/main/java/com/baeldung/jackson/serialization/jsonrootname/Author.java
deleted file mode 100644
index c6ebfd10fb..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/serialization/jsonrootname/Author.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package com.baeldung.jackson.serialization.jsonrootname;
-
-import com.baeldung.jackson.domain.Item;
-import com.baeldung.jackson.domain.Person;
-import com.fasterxml.jackson.annotation.JsonRootName;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-@JsonRootName("writer")
-public class Author extends Person {
-
- List
- items = new ArrayList<>();
-
- public Author(String firstName, String lastName) {
- super(firstName, lastName);
- }
-
- public List
- getItems() {
- return items;
- }
-
- public void setItems(List
- items) {
- this.items = items;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/serialization/jsonserialize/Author.java b/jackson/src/main/java/com/baeldung/jackson/serialization/jsonserialize/Author.java
deleted file mode 100644
index 5a6e90d712..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/serialization/jsonserialize/Author.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package com.baeldung.jackson.serialization.jsonserialize;
-
-import com.baeldung.jackson.domain.Person;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Author extends Person {
-
- List
items = new ArrayList<>();
-
- public Author(String firstName, String lastName) {
- super(firstName, lastName);
- }
-
- public List getItems() {
- return items;
- }
-
- public void setItems(List items) {
- this.items = items;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/serialization/jsonserialize/Book.java b/jackson/src/main/java/com/baeldung/jackson/serialization/jsonserialize/Book.java
deleted file mode 100644
index 0ecc4e72ce..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/serialization/jsonserialize/Book.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package com.baeldung.jackson.serialization.jsonserialize;
-
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
-import java.math.BigDecimal;
-import java.util.Date;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Book extends Item {
-
- private String ISBN;
-
- @JsonSerialize(using = CustomDateSerializer.class)
- private Date published;
- private BigDecimal pages;
-
- public Book() {
- }
-
- public Book(String title, Author author) {
- super(title, author);
- }
-
- public String getISBN() {
- return ISBN;
- }
-
- public void setISBN(String ISBN) {
- this.ISBN = ISBN;
- }
-
- public Date getPublished() {
- return published;
- }
-
- public void setPublished(Date published) {
- this.published = published;
- }
-
- public BigDecimal getPages() {
- return pages;
- }
-
- public void setPages(BigDecimal pages) {
- this.pages = pages;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/serialization/jsonserialize/CustomDateSerializer.java b/jackson/src/main/java/com/baeldung/jackson/serialization/jsonserialize/CustomDateSerializer.java
deleted file mode 100644
index 131f4f3695..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/serialization/jsonserialize/CustomDateSerializer.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.baeldung.jackson.serialization.jsonserialize;
-
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.SerializerProvider;
-import com.fasterxml.jackson.databind.ser.std.StdSerializer;
-
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class CustomDateSerializer extends StdSerializer {
-
- private static SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
-
- public CustomDateSerializer() {
- this(null);
- }
-
- public CustomDateSerializer(Class t) {
- super(t);
- }
-
- @Override
- public void serialize(Date value, JsonGenerator gen, SerializerProvider arg2) throws IOException, JsonProcessingException {
- gen.writeString(formatter.format(value));
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/serialization/jsonserialize/Item.java b/jackson/src/main/java/com/baeldung/jackson/serialization/jsonserialize/Item.java
deleted file mode 100644
index 56cfa85793..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/serialization/jsonserialize/Item.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package com.baeldung.jackson.serialization.jsonserialize;
-
-import com.baeldung.jackson.domain.Person;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Item {
-
- private UUID id;
- private String title;
- private List authors = new ArrayList<>();
- private float price;
-
- public Item() {
- }
-
- public Item(String title, Author author) {
- this.id = UUID.randomUUID();
- this.title = title;
- this.authors.add(author);
- }
-
- public UUID getId() {
- return id;
- }
-
- public void setId(UUID id) {
- this.id = id;
- }
-
- public String getTitle() {
- return title;
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- public List getAuthors() {
- return authors;
- }
-
- public void setAuthors(List authors) {
- this.authors = authors;
- }
-
- public float getPrice() {
- return price;
- }
-
- public void setPrice(float price) {
- this.price = price;
- }
-}
diff --git a/jackson/src/main/java/com/baeldung/jackson/serialization/jsonvalue/Course.java b/jackson/src/main/java/com/baeldung/jackson/serialization/jsonvalue/Course.java
deleted file mode 100644
index a3fdc2d8eb..0000000000
--- a/jackson/src/main/java/com/baeldung/jackson/serialization/jsonvalue/Course.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package com.baeldung.jackson.serialization.jsonvalue;
-
-import com.baeldung.jackson.domain.Author;
-import com.baeldung.jackson.domain.Item;
-import com.fasterxml.jackson.annotation.JsonValue;
-
-import java.util.List;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Course extends Item {
-
- public enum Medium {
- CLASSROOM, ONLINE
- }
-
- public enum Level {
- BEGINNER("Beginner", 1), INTERMEDIATE("Intermediate", 2), ADVANCED("Advanced", 3);
-
- private String name;
- private int number;
-
- Level(String name, int number) {
- this.name = name;
- this.number = number;
- }
-
- @JsonValue
- public String getName() {
- return name;
- }
- }
-
- private float duration;
- private Medium medium;
- private Level level;
- private List prerequisite;
-
- public Course(String title, Author author) {
- super(title, author);
- }
-
- public float getDuration() {
- return duration;
- }
-
- public void setDuration(float duration) {
- this.duration = duration;
- }
-
- public Medium getMedium() {
- return medium;
- }
-
- public void setMedium(Medium medium) {
- this.medium = medium;
- }
-
- public Level getLevel() {
- return level;
- }
-
- public void setLevel(Level level) {
- this.level = level;
- }
-
- public List getPrerequisite() {
- return prerequisite;
- }
-
- public void setPrerequisite(List prerequisite) {
- this.prerequisite = prerequisite;
- }
-}
diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/AliasBean.java b/jackson/src/test/java/com/baeldung/jackson/annotation/AliasBean.java
new file mode 100644
index 0000000000..1842b2b6f5
--- /dev/null
+++ b/jackson/src/test/java/com/baeldung/jackson/annotation/AliasBean.java
@@ -0,0 +1,31 @@
+package com.baeldung.jackson.annotation;
+
+import com.fasterxml.jackson.annotation.JsonAlias;
+
+public class AliasBean {
+
+ @JsonAlias({ "fName", "f_name" })
+ private String firstName;
+
+ private String lastName;
+
+ public AliasBean() {
+
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+}
diff --git a/jackson/src/test/java/com/baeldung/jackson/deserialization/jacksoninject/JacksonInjectUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/deserialization/jacksoninject/JacksonInjectUnitTest.java
deleted file mode 100644
index 96dbff6f3c..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/deserialization/jacksoninject/JacksonInjectUnitTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package com.baeldung.jackson.deserialization.jacksoninject;
-
-import com.fasterxml.jackson.databind.InjectableValues;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.util.UUID;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class JacksonInjectUnitTest {
-
- @Test
- public void whenDeserializingUsingJacksonInject_thenCorrect() throws IOException {
-
- UUID id = UUID.fromString("9616dc8c-bad3-11e6-a4a6-cec0c932ce01");
-
- // arrange
- String authorJson = "{\"firstName\": \"Alex\", \"lastName\": \"Theedom\"}";
-
- // act
- InjectableValues inject = new InjectableValues.Std().addValue(UUID.class, id);
- Author author = new ObjectMapper().reader(inject)
- .forType(Author.class)
- .readValue(authorJson);
-
- // assert
- assertThat(author.getId()).isEqualTo(id);
-
- /*
- {
- "firstName": "Alex",
- "lastName": "Theedom",
- "publications": []
- }
- */
-
- }
-}
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/deserialization/jsonanysetter/JsonAnySetterUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/deserialization/jsonanysetter/JsonAnySetterUnitTest.java
deleted file mode 100644
index 2e1f94bc3c..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/deserialization/jsonanysetter/JsonAnySetterUnitTest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package com.baeldung.jackson.deserialization.jsonanysetter;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import java.io.IOException;
-
-import static io.restassured.path.json.JsonPath.from;
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class JsonAnySetterUnitTest {
-
- @Test
- public void whenDeserializingUsingJsonAnySetter_thenCorrect() throws IOException {
-
- // arrange
- String json = "{\"USA\":10.00,\"UK\":15.00,\"China\":23.00,\"Brazil\":12.00,\"France\":8.00,\"Russia\":18.00}";
-
- // act
- Inventory inventory = new ObjectMapper().readerFor(Inventory.class)
- .readValue(json);
-
- // assert
- assertThat(from(json).getMap(".")
- .get("USA")).isEqualTo(inventory.getCountryDeliveryCost()
- .get("USA"));
- assertThat(from(json).getMap(".")
- .get("UK")).isEqualTo(inventory.getCountryDeliveryCost()
- .get("UK"));
- assertThat(from(json).getMap(".")
- .get("China")).isEqualTo(inventory.getCountryDeliveryCost()
- .get("China"));
- assertThat(from(json).getMap(".")
- .get("Brazil")).isEqualTo(inventory.getCountryDeliveryCost()
- .get("Brazil"));
- assertThat(from(json).getMap(".")
- .get("France")).isEqualTo(inventory.getCountryDeliveryCost()
- .get("France"));
- assertThat(from(json).getMap(".")
- .get("Russia")).isEqualTo(inventory.getCountryDeliveryCost()
- .get("Russia"));
-
- }
-}
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/deserialization/jsoncreator/JsonCreatorUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/deserialization/jsoncreator/JsonCreatorUnitTest.java
deleted file mode 100644
index cc245dab66..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/deserialization/jsoncreator/JsonCreatorUnitTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.baeldung.jackson.deserialization.jsoncreator;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import java.io.IOException;
-
-import static io.restassured.path.json.JsonPath.from;
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class JsonCreatorUnitTest {
-
- @Test
- public void whenDeserializingUsingJsonCreator_thenCorrect() throws IOException {
-
- // arrange
- String authorJson = "{" + " \"christianName\": \"Alex\"," + " \"surname\": \"Theedom\"" + "}";
-
- // act
- final Author author = new ObjectMapper().readerFor(Author.class)
- .readValue(authorJson);
-
- // assert
- assertThat(from(authorJson).getString("christianName")).isEqualTo(author.getFirstName());
- assertThat(from(authorJson).getString("surname")).isEqualTo(author.getLastName());
-
- /*
- {
- "christianName": "Alex",
- "surname": "Theedom"
- }
- */
-
- }
-}
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/deserialization/jsondeserialize/JsonDeserializeUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/deserialization/jsondeserialize/JsonDeserializeUnitTest.java
deleted file mode 100644
index 1bcde998d6..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/deserialization/jsondeserialize/JsonDeserializeUnitTest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.baeldung.jackson.deserialization.jsondeserialize;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-
-import static io.restassured.path.json.JsonPath.from;
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class JsonDeserializeUnitTest {
-
- @Test
- public void whenDeserializingUsingJsonDeserialize_thenCorrect() throws IOException {
-
- // arrange
- String bookJson = "{\"id\":\"957c43f2-fa2e-42f9-bf75-6e3d5bb6960a\",\"title\":\"Effective Java\",\"authors\":[{\"id\":\"9bcd817d-0141-42e6-8f04-e5aaab0980b6\",\"firstName\":\"Joshua\",\"lastName\":\"Bloch\"}],\"price\":0,\"published\":\"25-12-2017 13:30:25\",\"pages\":null,\"isbn\":null}";
-
- // act
- Book book = new ObjectMapper().readerFor(Book.class)
- .readValue(bookJson);
-
- // assert
- SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
- assertThat(from(bookJson).getString("published")).isEqualTo(df.format(book.getPublished()));
-
- }
-}
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/deserialization/jsonsetter/JsonSetterUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/deserialization/jsonsetter/JsonSetterUnitTest.java
deleted file mode 100644
index 4379fe376c..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/deserialization/jsonsetter/JsonSetterUnitTest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.baeldung.jackson.deserialization.jsonsetter;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import java.io.IOException;
-
-import static io.restassured.path.json.JsonPath.from;
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class JsonSetterUnitTest {
-
- @Test
- public void whenDeserializingUsingJsonSetter_thenCorrect() throws IOException {
-
- // arrange
- String json = "{\"firstName\":\"Alex\",\"lastName\":\"Theedom\",\"publications\":[{\"title\":\"Professional Java EE Design Patterns\"}]}";
-
- // act
- Author author = new ObjectMapper().readerFor(Author.class)
- .readValue(json);
-
- // assert
- assertThat(from(json).getList("publications")
- .size()).isEqualTo(author.getItems()
- .size());
-
- }
-}
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/dtos/Address.java b/jackson/src/test/java/com/baeldung/jackson/dtos/Address.java
index 19e7d4c53c..985851f456 100644
--- a/jackson/src/test/java/com/baeldung/jackson/dtos/Address.java
+++ b/jackson/src/test/java/com/baeldung/jackson/dtos/Address.java
@@ -1,16 +1,9 @@
package com.baeldung.jackson.dtos;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
-
public class Address {
- @JacksonXmlProperty(localName = "street_number")
String streetNumber;
-
- @JacksonXmlProperty(localName = "street_name")
String streetName;
-
- @JacksonXmlProperty(localName = "city")
String city;
public String getStreetNumber() {
diff --git a/jackson/src/test/java/com/baeldung/jackson/dtos/Person.java b/jackson/src/test/java/com/baeldung/jackson/dtos/Person.java
index 7891595cc6..13093cdcad 100644
--- a/jackson/src/test/java/com/baeldung/jackson/dtos/Person.java
+++ b/jackson/src/test/java/com/baeldung/jackson/dtos/Person.java
@@ -3,16 +3,13 @@ package com.baeldung.jackson.dtos;
import java.util.ArrayList;
import java.util.List;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
@JacksonXmlRootElement(localName = "person")
public final class Person {
private String firstName;
private String lastName;
- @JacksonXmlElementWrapper(useWrapping = false)
private List phoneNumbers = new ArrayList<>();
- @JacksonXmlElementWrapper(localName = "addresses")
private List address = new ArrayList<>();
public List getAddress() {
@@ -38,6 +35,7 @@ public final class Person {
public void setLastName(String lastName) {
this.lastName = lastName;
}
+
public List getPhoneNumbers() {
return phoneNumbers;
}
@@ -46,6 +44,4 @@ public final class Person {
this.phoneNumbers = phoneNumbers;
}
-
-
}
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/exception/UserWithRootNamespace.java b/jackson/src/test/java/com/baeldung/jackson/exception/UserWithRootNamespace.java
new file mode 100644
index 0000000000..bf8c85efba
--- /dev/null
+++ b/jackson/src/test/java/com/baeldung/jackson/exception/UserWithRootNamespace.java
@@ -0,0 +1,18 @@
+package com.baeldung.jackson.exception;
+
+import com.fasterxml.jackson.annotation.JsonRootName;
+
+@JsonRootName(value = "user", namespace="users")
+public class UserWithRootNamespace {
+ public int id;
+ public String name;
+
+ public UserWithRootNamespace() {
+ super();
+ }
+
+ public UserWithRootNamespace(final int id, final String name) {
+ this.id = id;
+ this.name = name;
+ }
+}
diff --git a/jackson/src/test/java/com/baeldung/jackson/general/jsonfilter/Author.java b/jackson/src/test/java/com/baeldung/jackson/general/jsonfilter/Author.java
deleted file mode 100644
index 3d5a9c907c..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/general/jsonfilter/Author.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package com.baeldung.jackson.general.jsonfilter;
-
-import com.baeldung.jackson.domain.Person;
-import com.baeldung.jackson.domain.Item;
-import com.fasterxml.jackson.annotation.JsonFilter;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-@JsonFilter("authorFilter")
-public class Author extends Person {
-
- private List- items = new ArrayList<>();
-
- public Author(String firstName, String lastName) {
- super(firstName, lastName);
- }
-
- public List
- getItems() {
- return items;
- }
-
- public void setItems(List
- items) {
- this.items = items;
- }
-}
diff --git a/jackson/src/test/java/com/baeldung/jackson/general/jsonfilter/JsonFilterUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/general/jsonfilter/JsonFilterUnitTest.java
deleted file mode 100644
index 6fcc57faa7..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/general/jsonfilter/JsonFilterUnitTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package com.baeldung.jackson.general.jsonfilter;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.ser.FilterProvider;
-import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
-import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
-import org.junit.Test;
-
-import static io.restassured.path.json.JsonPath.from;
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class JsonFilterUnitTest {
-
- @Test
- public void whenSerializingUsingJsonFilter_thenCorrect() throws JsonProcessingException {
-
- // arrange
- Author author = new Author("Alex", "Theedom");
- FilterProvider filters = new SimpleFilterProvider().addFilter("authorFilter", SimpleBeanPropertyFilter.filterOutAllExcept("lastName"));
-
- // act
- String result = new ObjectMapper().writer(filters)
- .writeValueAsString(author);
-
- // assert
- assertThat(from(result).getList("items")).isNull();
-
- /*
- {
- "lastName": "Theedom"
- }
- */
-
- }
-}
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/general/jsonformat/Book.java b/jackson/src/test/java/com/baeldung/jackson/general/jsonformat/Book.java
deleted file mode 100644
index e2eb4aa48a..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/general/jsonformat/Book.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package com.baeldung.jackson.general.jsonformat;
-
-import com.baeldung.jackson.domain.Author;
-import com.baeldung.jackson.domain.Item;
-import com.fasterxml.jackson.annotation.JsonFormat;
-
-import java.math.BigDecimal;
-import java.util.Date;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Book extends Item {
-
- private String ISBN;
-
- @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy HH:mm:ss")
- private Date published;
- private BigDecimal pages;
-
- public Book() {
- }
-
- public Book(String title, Author author) {
- super(title, author);
- }
-
- public String getISBN() {
- return ISBN;
- }
-
- public void setISBN(String ISBN) {
- this.ISBN = ISBN;
- }
-
- public Date getPublished() {
- return published;
- }
-
- public void setPublished(Date published) {
- this.published = published;
- }
-
- public BigDecimal getPages() {
- return pages;
- }
-
- public void setPages(BigDecimal pages) {
- this.pages = pages;
- }
-}
diff --git a/jackson/src/test/java/com/baeldung/jackson/general/jsonformat/JsonFormatUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/general/jsonformat/JsonFormatUnitTest.java
deleted file mode 100644
index 1fe217cef6..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/general/jsonformat/JsonFormatUnitTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package com.baeldung.jackson.general.jsonformat;
-
-import com.baeldung.jackson.domain.Author;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.TimeZone;
-
-import static io.restassured.path.json.JsonPath.from;
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class JsonFormatUnitTest {
-
- @Test
- public void whenSerializingUsingJsonFormat_thenCorrect() throws JsonProcessingException, ParseException {
-
- // arrange
- SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
- df.setTimeZone(TimeZone.getTimeZone("UTC"));
-
- String toParse = "20-12-2014 14:30:00";
- Date date = df.parse(toParse);
-
- Book book = new Book("Design Patterns: Elements of Reusable Object-oriented Software", new Author("The", "GoF"));
- book.setPublished(date);
-
- // act
- String result = new ObjectMapper().writeValueAsString(book);
-
- // assert
- assertThat(from(result).getString("published")).isEqualTo(toParse);
-
- /*
- {
- "id": "762b39be-fd5b-489e-8688-aeb3b9bbf019",
- "title": "Design Patterns: Elements of Reusable Object-oriented Software",
- "authors": [
- {
- "id": "6941b780-0f54-4259-adcb-85523c8f25f4",
- "firstName": "The",
- "lastName": "GoF",
- "items": []
- }
- ],
- "price": 0,
- "published": "20-12-2014 02:30:00",
- "pages": null,
- "isbn": null
- }
- */
-
- }
-}
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/general/jsonidentityinfo/Author.java b/jackson/src/test/java/com/baeldung/jackson/general/jsonidentityinfo/Author.java
deleted file mode 100644
index 1f36b95b2a..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/general/jsonidentityinfo/Author.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.baeldung.jackson.general.jsonidentityinfo;
-
-import com.fasterxml.jackson.annotation.JsonIdentityInfo;
-import com.fasterxml.jackson.annotation.ObjectIdGenerators;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
-public class Author extends Person {
-
- private List
- items = new ArrayList<>();
-
- public Author(String firstName, String lastName) {
- super(firstName, lastName);
- }
-
- public List
- getItems() {
- return items;
- }
-
- public void setItems(List
- items) {
- this.items = items;
- }
-}
diff --git a/jackson/src/test/java/com/baeldung/jackson/general/jsonidentityinfo/Course.java b/jackson/src/test/java/com/baeldung/jackson/general/jsonidentityinfo/Course.java
deleted file mode 100644
index 80dd9c275e..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/general/jsonidentityinfo/Course.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package com.baeldung.jackson.general.jsonidentityinfo;
-
-import java.util.List;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Course extends Item {
-
- public enum Medium {
- CLASSROOM, ONLINE
- }
-
- public enum Level {
- BEGINNER("Beginner", 1), INTERMEDIATE("Intermediate", 2), ADVANCED("Advanced", 3);
-
- private String name;
- private int number;
-
- Level(String name, int number) {
- this.name = name;
- this.number = number;
- }
-
- public String getName() {
- return name;
- }
- }
-
- private float duration;
- private Medium medium;
- private Level level;
- private List
prerequisite;
-
- public Course(String title, Author author) {
- super(title, author);
- }
-
- public float getDuration() {
- return duration;
- }
-
- public void setDuration(float duration) {
- this.duration = duration;
- }
-
- public Medium getMedium() {
- return medium;
- }
-
- public void setMedium(Medium medium) {
- this.medium = medium;
- }
-
- public Level getLevel() {
- return level;
- }
-
- public void setLevel(Level level) {
- this.level = level;
- }
-
- public List getPrerequisite() {
- return prerequisite;
- }
-
- public void setPrerequisite(List prerequisite) {
- this.prerequisite = prerequisite;
- }
-}
diff --git a/jackson/src/test/java/com/baeldung/jackson/general/jsonidentityinfo/Item.java b/jackson/src/test/java/com/baeldung/jackson/general/jsonidentityinfo/Item.java
deleted file mode 100644
index bad6562122..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/general/jsonidentityinfo/Item.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package com.baeldung.jackson.general.jsonidentityinfo;
-
-import com.fasterxml.jackson.annotation.JsonIdentityInfo;
-import com.fasterxml.jackson.annotation.ObjectIdGenerators;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
-public class Item {
-
- private UUID id;
- private String title;
- private List authors = new ArrayList<>();
- private float price;
-
- public Item() {
- }
-
- public Item(String title, Author author) {
- this.id = UUID.randomUUID();
- this.title = title;
- this.authors.add(author);
- }
-
- public UUID getId() {
- return id;
- }
-
- public void setId(UUID id) {
- this.id = id;
- }
-
- public String getTitle() {
- return title;
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- public List getAuthors() {
- return authors;
- }
-
- public void setAuthors(List authors) {
- this.authors = authors;
- }
-
- public float getPrice() {
- return price;
- }
-
- public void setPrice(float price) {
- this.price = price;
- }
-}
diff --git a/jackson/src/test/java/com/baeldung/jackson/general/jsonidentityinfo/JsonIdentityInfoUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/general/jsonidentityinfo/JsonIdentityInfoUnitTest.java
deleted file mode 100644
index 014f1a8f69..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/general/jsonidentityinfo/JsonIdentityInfoUnitTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package com.baeldung.jackson.general.jsonidentityinfo;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import java.util.Collections;
-
-import static io.restassured.path.json.JsonPath.from;
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class JsonIdentityInfoUnitTest {
-
- @Test
- public void whenSerializingUsingJsonIdentityInfo_thenCorrect() throws JsonProcessingException {
-
- // arrange
- Author author = new Author("Alex", "Theedom");
-
- Course course = new Course("Java EE Introduction", author);
- author.setItems(Collections.singletonList(course));
- course.setAuthors(Collections.singletonList(author));
-
- // act
- String result = new ObjectMapper().writeValueAsString(author);
-
- // assert
- assertThat(from(result).getString("items[0].authors")).isNotNull();
-
- /*
- Authors are included.
- {
- "id": "1b408bf9-5946-4a14-a112-fde2953a7fe7",
- "firstName": "Alex",
- "lastName": "Theedom",
- "items": [
- {
- "id": "5ed30530-f0a5-42eb-b786-be2c655da968",
- "title": "Java EE Introduction",
- "authors": [
- "1b408bf9-5946-4a14-a112-fde2953a7fe7"
- ],
- "price": 0,
- "duration": 0,
- "medium": null,
- "level": null,
- "prerequisite": null
- }
- ]
- }
- */
-
- }
-}
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/general/jsonidentityinfo/Person.java b/jackson/src/test/java/com/baeldung/jackson/general/jsonidentityinfo/Person.java
deleted file mode 100644
index ea80814124..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/general/jsonidentityinfo/Person.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.baeldung.jackson.general.jsonidentityinfo;
-
-import java.util.UUID;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Person {
-
- private UUID id;
- private String firstName;
- private String lastName;
-
- public Person() {
- }
-
- public Person(String firstName, String lastName) {
- this.id = UUID.randomUUID();
- this.firstName = firstName;
- this.lastName = lastName;
- }
-
- public String getFirstName() {
- return firstName;
- }
-
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
-
- public String getLastName() {
- return lastName;
- }
-
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
-
- public UUID getId() {
- return id;
- }
-}
diff --git a/jackson/src/test/java/com/baeldung/jackson/general/jsonproperty/Author.java b/jackson/src/test/java/com/baeldung/jackson/general/jsonproperty/Author.java
deleted file mode 100644
index 01552df729..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/general/jsonproperty/Author.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package com.baeldung.jackson.general.jsonproperty;
-
-import com.baeldung.jackson.domain.Person;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Author extends Person {
-
- private List- items = new ArrayList<>();
-
- public Author(String firstName, String lastName) {
- super(firstName, lastName);
- }
-
- public List
- getItems() {
- return items;
- }
-
- public void setItems(List
- items) {
- this.items = items;
- }
-}
diff --git a/jackson/src/test/java/com/baeldung/jackson/general/jsonproperty/Book.java b/jackson/src/test/java/com/baeldung/jackson/general/jsonproperty/Book.java
deleted file mode 100644
index 100d9634f5..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/general/jsonproperty/Book.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package com.baeldung.jackson.general.jsonproperty;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-import java.math.BigDecimal;
-import java.util.Date;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Book extends Item {
-
- private String ISBN;
- private Date published;
- private BigDecimal pages;
- private String binding;
-
- public Book() {
- }
-
- public Book(String title, Author author) {
- super(title, author);
- }
-
- public String getISBN() {
- return ISBN;
- }
-
- public void setISBN(String ISBN) {
- this.ISBN = ISBN;
- }
-
- public Date getPublished() {
- return published;
- }
-
- public void setPublished(Date published) {
- this.published = published;
- }
-
- public BigDecimal getPages() {
- return pages;
- }
-
- public void setPages(BigDecimal pages) {
- this.pages = pages;
- }
-
- @JsonProperty("binding")
- public String coverBinding() {
- return binding;
- }
-
- @JsonProperty("binding")
- public void configureBinding(String binding) {
- this.binding = binding;
- }
-}
diff --git a/jackson/src/test/java/com/baeldung/jackson/general/jsonproperty/Item.java b/jackson/src/test/java/com/baeldung/jackson/general/jsonproperty/Item.java
deleted file mode 100644
index d7ee430d51..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/general/jsonproperty/Item.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package com.baeldung.jackson.general.jsonproperty;
-
-import com.baeldung.jackson.domain.Person;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Item {
-
- private UUID id;
- private String title;
- private List
authors = new ArrayList<>();
- private float price;
-
- public Item() {
- }
-
- public Item(String title, Author author) {
- this.id = UUID.randomUUID();
- this.title = title;
- this.authors.add(author);
- }
-
- public UUID getId() {
- return id;
- }
-
- public void setId(UUID id) {
- this.id = id;
- }
-
- public String getTitle() {
- return title;
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- public List getAuthors() {
- return authors;
- }
-
- public void setAuthors(List authors) {
- this.authors = authors;
- }
-
- public float getPrice() {
- return price;
- }
-
- public void setPrice(float price) {
- this.price = price;
- }
-}
diff --git a/jackson/src/test/java/com/baeldung/jackson/general/jsonproperty/JsonPropertyUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/general/jsonproperty/JsonPropertyUnitTest.java
deleted file mode 100644
index 0b88e7fc47..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/general/jsonproperty/JsonPropertyUnitTest.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package com.baeldung.jackson.general.jsonproperty;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import java.io.IOException;
-
-import static io.restassured.path.json.JsonPath.from;
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class JsonPropertyUnitTest {
-
- @Test
- public void whenSerializingUsingJsonProperty_thenCorrect() throws JsonProcessingException {
-
- // arrange
- Book book = new Book("Design Patterns: Elements of Reusable Object-oriented Software", new Author("The", "GoF"));
- book.configureBinding("Hardback");
-
- // act
- String result = new ObjectMapper().writeValueAsString(book);
-
- // assert
- assertThat(from(result).getString("binding")).isEqualTo("Hardback");
-
- /*
- {
- "id": "cd941587-d1ae-4c2a-9a36-29533bf50411",
- "title": "Design Patterns: Elements of Reusable Object-oriented Software",
- "authors": [
- {
- "id": "c8e26318-2f5b-4fa2-9fdc-6e99be021fca",
- "firstName": "The",
- "lastName": "GoF",
- "items": []
- }
- ],
- "price": 0,
- "published": null,
- "pages": null,
- "isbn": null,
- "binding": "Hardback"
- }
- */
-
- }
-
- @Test
- public void whenDeserializingUsingJsonProperty_thenCorrect() throws IOException {
-
- // arrange
- String result = "{\"id\":\"cd941587-d1ae-4c2a-9a36-29533bf50411\",\"title\":\"Design Patterns: Elements of Reusable Object-oriented Software\",\"authors\":[{\"id\":\"c8e26318-2f5b-4fa2-9fdc-6e99be021fca\",\"firstName\":\"The\",\"lastName\":\"GoF\"}],\"binding\":\"Hardback\"}";
-
- // act
- Book book = new ObjectMapper().readerFor(Book.class)
- .readValue(result);
-
- // assert
- assertThat(book.coverBinding()).isEqualTo("Hardback");
-
- }
-
-}
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/general/jsonunwrapped/JsonUnwrappedUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/general/jsonunwrapped/JsonUnwrappedUnitTest.java
deleted file mode 100644
index 5130e037d5..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/general/jsonunwrapped/JsonUnwrappedUnitTest.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.baeldung.jackson.general.jsonunwrapped;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import static io.restassured.path.json.JsonPath.from;
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class JsonUnwrappedUnitTest {
-
- @Test
- public void whenSerializingUsingJsonUnwrapped_thenCorrect() throws JsonProcessingException {
-
- // arrange
- Order.Type preorderType = new Order.Type();
- preorderType.id = 10;
- preorderType.name = "pre-order";
-
- Order order = new Order(preorderType);
-
- // act
- String result = new ObjectMapper().writeValueAsString(order);
-
- // assert
- assertThat(from(result).getInt("id")).isEqualTo(10);
- assertThat(from(result).getString("name")).isEqualTo("pre-order");
-
- /*
- {
- "id": 10,
- "name": "pre-order"
- }
- */
-
- }
-}
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/general/jsonunwrapped/Order.java b/jackson/src/test/java/com/baeldung/jackson/general/jsonunwrapped/Order.java
deleted file mode 100644
index b1c5b832c3..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/general/jsonunwrapped/Order.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package com.baeldung.jackson.general.jsonunwrapped;
-
-import com.fasterxml.jackson.annotation.JsonUnwrapped;
-
-import java.util.UUID;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Order {
-
- private UUID id;
-
- @JsonUnwrapped
- private Type type;
- private int internalAudit;
-
- public static class Type {
- public long id;
- public String name;
- }
-
- public Order() {
- this.id = UUID.randomUUID();
- }
-
- public Order(Type type) {
- this();
- this.type = type;
- }
-
- public Order(int internalAudit) {
- this();
- this.type = new Type();
- this.type.id = 20;
- this.type.name = "Order";
- this.internalAudit = internalAudit;
- }
-
- public UUID getId() {
- return id;
- }
-
- public Type getType() {
- return type;
- }
-
- public void setType(Type type) {
- this.type = type;
- }
-}
diff --git a/jackson/src/test/java/com/baeldung/jackson/general/jsonview/JsonViewUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/general/jsonview/JsonViewUnitTest.java
deleted file mode 100644
index ab609008ce..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/general/jsonview/JsonViewUnitTest.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package com.baeldung.jackson.general.jsonview;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import static io.restassured.path.json.JsonPath.from;
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class JsonViewUnitTest {
-
- @Test
- public void whenSerializingUsingJsonView_andInternalView_thenCorrect() throws JsonProcessingException {
-
- // arrange
- Order order = new Order(120);
-
- // act
- String result = new ObjectMapper().writerWithView(Views.Internal.class)
- .writeValueAsString(order);
-
- // assert
- assertThat(from(result).getUUID("id")).isNotNull();
- assertThat(from(result).getObject("type", Order.Type.class)).isNotNull();
- assertThat(from(result).getInt("internalAudit")).isEqualTo(120);
-
- /*
- {
- "id": "33806388-795b-4812-b90a-60292111bc5c",
- "type": {
- "id": 20,
- "name": "Order"
- },
- "internalAudit": 120
- }
- */
-
- }
-
- @Test
- public void whenSerializingUsingJsonView_andPublicView_thenCorrect() throws JsonProcessingException {
-
- // arrange
- Order order = new Order(120);
-
- // act
- String result = new ObjectMapper().writerWithView(Views.Public.class)
- .writeValueAsString(order);
-
- // assert
- assertThat(from(result).getUUID("id")).isNotNull();
- assertThat(from(result).getObject("type", Order.Type.class)).isNotNull();
- assertThat(result).doesNotContain("internalAudit");
-
- /*
- {
- "id": "5184d5fc-e359-4cdf-93fa-4054025bef4e",
- "type": {
- "id": 20,
- "name": "Order"
- }
- }
- */
-
- }
-
-}
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/general/jsonview/Order.java b/jackson/src/test/java/com/baeldung/jackson/general/jsonview/Order.java
deleted file mode 100644
index 69adf1b59d..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/general/jsonview/Order.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package com.baeldung.jackson.general.jsonview;
-
-import com.fasterxml.jackson.annotation.JsonView;
-
-import java.util.UUID;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Order {
-
- @JsonView(Views.Public.class)
- private UUID id;
-
- @JsonView(Views.Public.class)
- private Type type;
-
- @JsonView(Views.Internal.class)
- private int internalAudit;
-
- public static class Type {
- public long id;
- public String name;
- }
-
- public Order() {
- this.id = UUID.randomUUID();
- }
-
- public Order(Type type) {
- this();
- this.type = type;
- }
-
- public Order(int internalAudit) {
- this();
- this.type = new Type();
- this.type.id = 20;
- this.type.name = "Order";
- this.internalAudit = internalAudit;
- }
-
- public UUID getId() {
- return id;
- }
-
- public Type getType() {
- return type;
- }
-
- public void setType(Type type) {
- this.type = type;
- }
-}
diff --git a/jackson/src/test/java/com/baeldung/jackson/general/jsonview/Views.java b/jackson/src/test/java/com/baeldung/jackson/general/jsonview/Views.java
deleted file mode 100644
index b55997554d..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/general/jsonview/Views.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.baeldung.jackson.general.jsonview;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Views {
- public static class Public {
- }
-
- public static class Internal extends Public {
- }
-}
diff --git a/jackson/src/test/java/com/baeldung/jackson/general/reference/Author.java b/jackson/src/test/java/com/baeldung/jackson/general/reference/Author.java
deleted file mode 100644
index 02dd9470d7..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/general/reference/Author.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.baeldung.jackson.general.reference;
-
-import com.fasterxml.jackson.annotation.JsonManagedReference;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Author extends Person {
-
- private List- items = new ArrayList<>();
-
- public Author(String firstName, String lastName) {
- super(firstName, lastName);
- }
-
- @JsonManagedReference
- public List
- getItems() {
- return items;
- }
-
- public void setItems(List
- items) {
- this.items = items;
- }
-}
diff --git a/jackson/src/test/java/com/baeldung/jackson/general/reference/Course.java b/jackson/src/test/java/com/baeldung/jackson/general/reference/Course.java
deleted file mode 100644
index 251d25a517..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/general/reference/Course.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package com.baeldung.jackson.general.reference;
-
-import java.util.List;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Course extends Item {
-
- public enum Medium {
- CLASSROOM, ONLINE
- }
-
- public enum Level {
- BEGINNER("Beginner", 1), INTERMEDIATE("Intermediate", 2), ADVANCED("Advanced", 3);
-
- private String name;
- private int number;
-
- Level(String name, int number) {
- this.name = name;
- this.number = number;
- }
-
- public String getName() {
- return name;
- }
- }
-
- private float duration;
- private Medium medium;
- private Level level;
- private List
prerequisite;
-
- public Course(String title, Author author) {
- super(title, author);
- }
-
- public float getDuration() {
- return duration;
- }
-
- public void setDuration(float duration) {
- this.duration = duration;
- }
-
- public Medium getMedium() {
- return medium;
- }
-
- public void setMedium(Medium medium) {
- this.medium = medium;
- }
-
- public Level getLevel() {
- return level;
- }
-
- public void setLevel(Level level) {
- this.level = level;
- }
-
- public List getPrerequisite() {
- return prerequisite;
- }
-
- public void setPrerequisite(List prerequisite) {
- this.prerequisite = prerequisite;
- }
-}
diff --git a/jackson/src/test/java/com/baeldung/jackson/general/reference/Item.java b/jackson/src/test/java/com/baeldung/jackson/general/reference/Item.java
deleted file mode 100644
index 5dd66a8ca3..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/general/reference/Item.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package com.baeldung.jackson.general.reference;
-
-import com.fasterxml.jackson.annotation.JsonBackReference;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Item {
-
- private UUID id;
- private String title;
-
- @JsonBackReference
- private List authors = new ArrayList<>();
- private float price;
-
- public Item() {
- }
-
- public Item(String title, Author author) {
- this.id = UUID.randomUUID();
- this.title = title;
- this.authors.add(author);
- }
-
- public UUID getId() {
- return id;
- }
-
- public void setId(UUID id) {
- this.id = id;
- }
-
- public String getTitle() {
- return title;
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- public List getAuthors() {
- return authors;
- }
-
- public void setAuthors(List authors) {
- this.authors = authors;
- }
-
- public float getPrice() {
- return price;
- }
-
- public void setPrice(float price) {
- this.price = price;
- }
-}
diff --git a/jackson/src/test/java/com/baeldung/jackson/general/reference/Person.java b/jackson/src/test/java/com/baeldung/jackson/general/reference/Person.java
deleted file mode 100644
index 95c0b35b8b..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/general/reference/Person.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.baeldung.jackson.general.reference;
-
-import java.util.UUID;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class Person {
-
- private UUID id;
- private String firstName;
- private String lastName;
-
- public Person() {
- }
-
- public Person(String firstName, String lastName) {
- this.id = UUID.randomUUID();
- this.firstName = firstName;
- this.lastName = lastName;
- }
-
- public String getFirstName() {
- return firstName;
- }
-
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
-
- public String getLastName() {
- return lastName;
- }
-
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
-
- public UUID getId() {
- return id;
- }
-}
diff --git a/jackson/src/test/java/com/baeldung/jackson/general/reference/ReferenceUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/general/reference/ReferenceUnitTest.java
deleted file mode 100644
index 7a52a69656..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/general/reference/ReferenceUnitTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.baeldung.jackson.general.reference;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import java.util.Collections;
-
-import static io.restassured.path.json.JsonPath.from;
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class ReferenceUnitTest {
-
- @Test
- public void whenSerializingUsingReference_thenCorrect() throws JsonProcessingException {
-
- // arrange
- Author author = new Author("Alex", "Theedom");
-
- Course course = new Course("Java EE Introduction", author);
- author.setItems(Collections.singletonList(course));
- course.setAuthors(Collections.singletonList(author));
-
- // act
- String result = new ObjectMapper().writeValueAsString(author);
-
- // assert
- assertThat(from(result).getString("items[0].authors")).isNull();
-
- /*
- Without references defined it throws StackOverflowError.
- Authors excluded.
-
- {
- "id": "9c45d9b3-4888-4c24-8b74-65ef35627cd7",
- "firstName": "Alex",
- "lastName": "Theedom",
- "items": [
- {
- "id": "f8309629-d178-4d67-93a4-b513ec4a7f47",
- "title": "Java EE Introduction",
- "price": 0,
- "duration": 0,
- "medium": null,
- "level": null,
- "prerequisite": null
- }
- ]
- }
- */
-
- }
-}
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/inclusion/jsonautodetect/JsonAutoDetectUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/inclusion/jsonautodetect/JsonAutoDetectUnitTest.java
deleted file mode 100644
index a3e29776a9..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/inclusion/jsonautodetect/JsonAutoDetectUnitTest.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package com.baeldung.jackson.inclusion.jsonautodetect;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import static io.restassured.path.json.JsonPath.from;
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class JsonAutoDetectUnitTest {
-
- @Test
- public void whenSerializingUsingJsonAutoDetect_thenCorrect() throws JsonProcessingException {
-
- // arrange
- Order order = new Order(1234567890);
-
- // act
- String result = new ObjectMapper().writeValueAsString(order);
-
- // assert
- assertThat(from(result).getInt("internalAudit")).isEqualTo(1234567890);
-
- /*
- With @JsonAutoDetect
- {
- "id": "c94774d9-de8f-4244-85d5-624bd3a4567a",
- "type": {
- "id": 20,
- "name": "Order"
- },
- "internalAudit": 1234567890
- }
-
- Without @JsonAutoDetect
- {
- "id": "c94774d9-de8f-4244-85d5-624bd3a4567a",
- "type": {
- "id": 20,
- "name": "Order"
- }
- }
- */
-
- }
-}
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/inclusion/jsonignore/JsonIgnoreUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/inclusion/jsonignore/JsonIgnoreUnitTest.java
deleted file mode 100644
index 89e3c15f04..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/inclusion/jsonignore/JsonIgnoreUnitTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.baeldung.jackson.inclusion.jsonignore;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import static io.restassured.path.json.JsonPath.from;
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class JsonIgnoreUnitTest {
-
- @Test
- public void whenSerializingUsingJsonIgnore_thenCorrect() throws JsonProcessingException {
-
- // arrange
- Author author = new Author("Alex", "Theedom");
-
- // act
- String result = new ObjectMapper().writeValueAsString(author);
-
- // assert
- assertThat(from(result).getString("firstName")).isEqualTo("Alex");
- assertThat(from(result).getString("lastName")).isEqualTo("Theedom");
- assertThat(from(result).getString("id")).isNull();
-
- /*
- {
- "firstName": "Alex",
- "lastName": "Theedom",
- "items": []
- }
- */
-
- }
-}
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/inclusion/jsonignoreproperties/JsonIgnorePropertiesUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/inclusion/jsonignoreproperties/JsonIgnorePropertiesUnitTest.java
deleted file mode 100644
index be20d242c9..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/inclusion/jsonignoreproperties/JsonIgnorePropertiesUnitTest.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package com.baeldung.jackson.inclusion.jsonignoreproperties;
-
-import com.baeldung.jackson.domain.Author;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import static io.restassured.path.json.JsonPath.from;
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class JsonIgnorePropertiesUnitTest {
-
- @Test
- public void whenSerializingUsingJsonIgnoreProperties_thenCorrect() throws JsonProcessingException {
-
- // arrange
- Course course = new Course("Spring Security", new Author("Eugen", "Paraschiv"));
- course.setMedium(Course.Medium.ONLINE);
-
- // act
- String result = new ObjectMapper().writeValueAsString(course);
-
- // assert
- assertThat(from(result).getString("medium")).isNull();
-
- /*
- {
- "id": "ef0c8d2b-b088-409e-905c-95ac88dc0ed0",
- "title": "Spring Security",
- "authors": [
- {
- "id": "47a4f498-b0f3-4daf-909f-d2c35a0fe3c2",
- "firstName": "Eugen",
- "lastName": "Paraschiv",
- "items": []
- }
- ],
- "price": 0,
- "duration": 0,
- "level": null,
- "prerequisite": null
- }
- */
-
- }
-}
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/inclusion/jsonignoretype/JsonIgnoreTypeUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/inclusion/jsonignoretype/JsonIgnoreTypeUnitTest.java
deleted file mode 100644
index e8917ff526..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/inclusion/jsonignoretype/JsonIgnoreTypeUnitTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.baeldung.jackson.inclusion.jsonignoretype;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import static io.restassured.path.json.JsonPath.from;
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class JsonIgnoreTypeUnitTest {
-
- @Test
- public void whenSerializingUsingJsonIgnoreType_thenCorrect() throws JsonProcessingException {
-
- // arrange
- Order.Type type = new Order.Type();
- type.id = 10;
- type.name = "Pre-order";
-
- Order order = new Order(type);
-
- // act
- String result = new ObjectMapper().writeValueAsString(order);
-
- // assert
- assertThat(from(result).getString("id")).isNotNull();
- assertThat(from(result).getString("type")).isNull();
-
- /*
- {"id":"ac2428da-523e-443c-a18a-4ea4d2791fea"}
- */
-
- }
-}
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/inclusion/jsoninclude/JsonIncludeUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/inclusion/jsoninclude/JsonIncludeUnitTest.java
deleted file mode 100644
index ca4c4b751a..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/inclusion/jsoninclude/JsonIncludeUnitTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.baeldung.jackson.inclusion.jsoninclude;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import static io.restassured.path.json.JsonPath.from;
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class JsonIncludeUnitTest {
-
- @Test
- public void whenSerializingUsingJsonInclude_thenCorrect() throws JsonProcessingException {
-
- // arrange
- Author author = new Author("Alex", null);
-
- // act
- String result = new ObjectMapper().writeValueAsString(author);
-
- // assert
- assertThat(from(result).getString("firstName")).isEqualTo("Alex");
- assertThat(result).doesNotContain("lastName");
-
- /*
- {
- "id": "e8bb4802-6e0c-4fa5-9f68-c233272399cd",
- "firstName": "Alex",
- "items": []
- }
- */
-
- }
-}
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/miscellaneous/custom/CustomUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/miscellaneous/custom/CustomUnitTest.java
deleted file mode 100644
index 8f90c02875..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/miscellaneous/custom/CustomUnitTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.baeldung.jackson.miscellaneous.custom;
-
-import com.baeldung.jackson.domain.Author;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import static io.restassured.path.json.JsonPath.from;
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class CustomUnitTest {
-
- @Test
- public void whenSerializingUsingCustom_thenCorrect() throws JsonProcessingException {
-
- // arrange
- Course course = new Course("Spring Security", new Author("Eugen", "Paraschiv"));
- course.setMedium(Course.Medium.ONLINE);
-
- // act
- String result = new ObjectMapper().writeValueAsString(course);
-
- // assert
- assertThat(from(result).getString("title")).isEqualTo("Spring Security");
-
- /*
- {
- "title": "Spring Security",
- "price": 0,
- "id": "7dfd4db9-1175-432f-a53b-687423f7bb9b",
- "duration": 0,
- "authors": [
- {
- "id": "da0738f6-033c-4974-8d87-92820e5ccf27",
- "firstName": "Eugen",
- "lastName": "Paraschiv",
- "items": []
- }
- ],
- "medium": "ONLINE"
- }
- */
-
- }
-}
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/miscellaneous/disable/DisableUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/miscellaneous/disable/DisableUnitTest.java
deleted file mode 100644
index f9bc14291e..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/miscellaneous/disable/DisableUnitTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package com.baeldung.jackson.miscellaneous.disable;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.MapperFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import static io.restassured.path.json.JsonPath.from;
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class DisableUnitTest {
-
- @Test
- public void whenSerializingUsingDisable_thenCorrect() throws JsonProcessingException {
-
- // arrange
- Author author = new Author("Alex", "Theedom");
-
- // act
- ObjectMapper mapper = new ObjectMapper();
- String result = mapper.writeValueAsString(author);
-
- // assert
- assertThat(from(result).getList("items")).isNull();
-
- /*
- {
- "lastName": "Theedom",
- "firstName": "Alex",
- "id": "de4afbb4-b24d-45c8-bb00-fd6b9acb42f1"
- }
- */
-
- // act
- mapper = new ObjectMapper();
- mapper.disable(MapperFeature.USE_ANNOTATIONS);
- result = mapper.writeValueAsString(author);
-
- // assert
- assertThat(from(result).getList("items")).isNotNull();
-
- /*
- {
- "id": "81e6ed72-6b27-4fe9-a36f-e3171c5b55ef",
- "firstName": "Alex",
- "lastName": "Theedom",
- "items": []
- }
- */
-
- }
-}
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/miscellaneous/mixin/MixInUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/miscellaneous/mixin/MixInUnitTest.java
deleted file mode 100644
index 732cda58d0..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/miscellaneous/mixin/MixInUnitTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package com.baeldung.jackson.miscellaneous.mixin;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import java.util.List;
-
-import static io.restassured.path.json.JsonPath.from;
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class MixInUnitTest {
-
- @Test
- public void whenSerializingUsingMixIn_thenCorrect() throws JsonProcessingException {
-
- // arrange
- Author author = new Author("Alex", "Theedom");
-
- // act
- String result = new ObjectMapper().writeValueAsString(author);
-
- // assert
- assertThat(from(result).getList("items")).isNotNull();
-
- /*
- {
- "id": "f848b076-00a4-444a-a50b-328595dd9bf5",
- "firstName": "Alex",
- "lastName": "Theedom",
- "items": []
- }
- */
-
- ObjectMapper mapper = new ObjectMapper();
- mapper.addMixIn(List.class, IgnoreListMixIn.class);
-
- result = mapper.writeValueAsString(author);
-
- // assert
- assertThat(from(result).getList("items")).isNull();
-
- /*
- {
- "id": "9ffefb7d-e56f-447c-9009-e92e142f8347",
- "firstName": "Alex",
- "lastName": "Theedom"
- }
- */
-
- }
-}
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/polymorphism/PolymorphismUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/polymorphism/PolymorphismUnitTest.java
deleted file mode 100644
index e922cf9976..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/polymorphism/PolymorphismUnitTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package com.baeldung.jackson.polymorphism;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import java.io.IOException;
-
-import static io.restassured.path.json.JsonPath.from;
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class PolymorphismUnitTest {
-
- @Test
- public void whenSerializingUsingPolymorphism_thenCorrect() throws JsonProcessingException {
-
- // arrange
- Order.InternalType internalType = new Order.InternalType();
- internalType.id = 250;
- internalType.name = "staff";
-
- Order order = new Order(internalType);
-
- // act
- String result = new ObjectMapper().writeValueAsString(order);
-
- // assert
- assertThat(from(result).getString("type.ordertype")).isEqualTo("internal");
-
- /*
- {
- "id": "7fc898e3-b4e7-41b0-8ffa-664cf3663f2e",
- "type": {
- "ordertype": "internal",
- "id": 250,
- "name": "staff"
- }
- }
- */
-
- }
-
- @Test
- public void whenDeserializingPolymorphic_thenCorrect() throws IOException {
-
- // arrange
- String orderJson = "{\"type\":{\"ordertype\":\"internal\",\"id\":100,\"name\":\"directors\"}}";
-
- // act
- Order order = new ObjectMapper().readerFor(Order.class)
- .readValue(orderJson);
-
- // assert
- assertThat(from(orderJson).getString("type.ordertype")).isEqualTo("internal");
- assertThat(((Order.InternalType) order.getType()).name).isEqualTo("directors");
- assertThat(((Order.InternalType) order.getType()).id).isEqualTo(100);
- assertThat(order.getType()
- .getClass()).isEqualTo(Order.InternalType.class);
- }
-}
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/serialization/jsonanygetter/JsonAnyGetterUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/serialization/jsonanygetter/JsonAnyGetterUnitTest.java
deleted file mode 100644
index 7a786e0bd6..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/serialization/jsonanygetter/JsonAnyGetterUnitTest.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package com.baeldung.jackson.serialization.jsonanygetter;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import java.util.Map;
-
-import static io.restassured.path.json.JsonPath.from;
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class JsonAnyGetterUnitTest {
-
- @Test
- public void whenSerializingUsingJsonAnyGetter_thenCorrect() throws JsonProcessingException {
-
- // arrange
- Inventory inventory = new Inventory();
- Map countryDeliveryCost = inventory.getCountryDeliveryCost();
- inventory.setLocation("France");
-
- countryDeliveryCost.put("USA", 10.00f);
- countryDeliveryCost.put("UK", 15.00f);
-
- // act
- String result = new ObjectMapper().writeValueAsString(inventory);
-
- // assert
- assertThat(from(result).getString("location")).isEqualTo("France");
- assertThat(from(result).getFloat("USA")).isEqualTo(10.00f);
- assertThat(from(result).getFloat("UK")).isEqualTo(15.00f);
-
- /*
- {
- "location": "France",
- "USA": 10,
- "UK": 15
- }
- */
-
- }
-
-}
diff --git a/jackson/src/test/java/com/baeldung/jackson/serialization/jsongetter/JsonGetterUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/serialization/jsongetter/JsonGetterUnitTest.java
deleted file mode 100644
index 4bc9c51e83..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/serialization/jsongetter/JsonGetterUnitTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.baeldung.jackson.serialization.jsongetter;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import static io.restassured.path.json.JsonPath.from;
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class JsonGetterUnitTest {
-
- @Test
- public void whenSerializingUsingJsonGetter_thenCorrect() throws JsonProcessingException {
-
- // arrange
- Author author = new Author("Alex", "Theedom");
-
- // act
- String result = new ObjectMapper().writeValueAsString(author);
-
- // assert
- assertThat(from(result).getList("publications")).isNotNull();
- assertThat(from(result).getList("items")).isNull();
-
- /*
- {
- "firstName": "Alex",
- "lastName": "Theedom",
- "publications": []
- }
- */
-
- }
-}
diff --git a/jackson/src/test/java/com/baeldung/jackson/serialization/jsonpropertyorder/JsonPropertyOrderUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/serialization/jsonpropertyorder/JsonPropertyOrderUnitTest.java
deleted file mode 100644
index 77ef85ed73..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/serialization/jsonpropertyorder/JsonPropertyOrderUnitTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package com.baeldung.jackson.serialization.jsonpropertyorder;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class JsonPropertyOrderUnitTest {
-
- @Test
- public void whenSerializingUsingJsonPropertyOrder_thenCorrect() throws JsonProcessingException {
-
- // arrange
- Author author = new Author("Alex", "Theedom");
-
- // act
- String result = new ObjectMapper().writeValueAsString(author);
-
- // assert
- assertThat(result, matchesJsonSchemaInClasspath("author-jsonpropertyorder-schema.json"));
-
- // NOTE: property order is not enforced by the JSON specification.
-
- /*
- {
- "items": [],
- "firstName": "Alex",
- "lastName": "Theedom",
- "id": "fd277638-9b6e-49f7-81c1-bc52f165245b"
- }
- */
-
- }
-}
diff --git a/jackson/src/test/java/com/baeldung/jackson/serialization/jsonrawvalue/JsonRawValueUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/serialization/jsonrawvalue/JsonRawValueUnitTest.java
deleted file mode 100644
index f0f0913aee..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/serialization/jsonrawvalue/JsonRawValueUnitTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.baeldung.jackson.serialization.jsonrawvalue;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class JsonRawValueUnitTest {
-
- @Test
- public void whenSerializingUsingJsonRawValue_thenCorrect() throws JsonProcessingException {
-
- // arrange
- String customerConfig = "{\"colour\":\"red\",\"device\":\"mobile\",\"orientation\":\"landscape\"}";
- Customer customer = new Customer("Alex", "Theedom");
- customer.setConfiguration("{\"colour\":\"red\",\"device\":\"mobile\",\"orientation\":\"landscape\"}");
-
- // act
- String result = new ObjectMapper().writeValueAsString(customer);
-
- // assert
- assertThat(result.contains(customerConfig));
-
- /*
- {
- "firstName": "Alex",
- "lastName": "Theedom",
- "publications": []
- }
- */
-
- }
-}
diff --git a/jackson/src/test/java/com/baeldung/jackson/serialization/jsonrootname/JsonRootNameUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/serialization/jsonrootname/JsonRootNameUnitTest.java
deleted file mode 100644
index cb54e63079..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/serialization/jsonrootname/JsonRootNameUnitTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package com.baeldung.jackson.serialization.jsonrootname;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import org.junit.Test;
-
-import static io.restassured.path.json.JsonPath.from;
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class JsonRootNameUnitTest {
-
- @Test
- public void whenSerializingUsingJsonRootName_thenCorrect() throws JsonProcessingException {
-
- // arrange
- Author author = new Author("Alex", "Theedom");
-
- // act
- ObjectMapper mapper = new ObjectMapper();
- mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
- String result = mapper.writeValueAsString(author);
-
- // assert
- assertThat(from(result).getString("writer.firstName")).isEqualTo("Alex");
- assertThat(from(result).getString("author.firstName")).isNull();
-
- /*
- {
- "writer": {
- "id": "0f50dca6-3dd7-4801-a334-fd1614276389",
- "firstName": "Alex",
- "lastName": "Theedom",
- "items": []
- }
- }
- */
-
- }
-}
diff --git a/jackson/src/test/java/com/baeldung/jackson/serialization/jsonserialize/JsonSerializeUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/serialization/jsonserialize/JsonSerializeUnitTest.java
deleted file mode 100644
index cca018e78d..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/serialization/jsonserialize/JsonSerializeUnitTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package com.baeldung.jackson.serialization.jsonserialize;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-
-import static io.restassured.path.json.JsonPath.from;
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class JsonSerializeUnitTest {
-
- @Test
- public void whenSerializingUsingJsonSerialize_thenCorrect() throws JsonProcessingException, ParseException {
-
- // arrange
- Author joshuaBloch = new Author("Joshua", "Bloch");
- Book book = new Book("Effective Java", joshuaBloch);
-
- SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
- String toParse = "25-12-2017 13:30:25";
- book.setPublished(df.parse(toParse));
-
- // act
- String result = new ObjectMapper().writeValueAsString(book);
-
- // assert
- assertThat(from(result).getString("published")).isEqualTo(toParse);
-
- /*
- {
- "id": "957c43f2-fa2e-42f9-bf75-6e3d5bb6960a",
- "title": "Effective Java",
- "authors": [
- {
- "id": "9bcd817d-0141-42e6-8f04-e5aaab0980b6",
- "firstName": "Joshua",
- "lastName": "Bloch",
- "items": []
- }
- ],
- "price": 0,
- "published": "25-12-2017 13:30:25",
- "pages": null,
- "isbn": null
- }
- */
-
- }
-}
diff --git a/jackson/src/test/java/com/baeldung/jackson/serialization/jsonvalue/JsonValueUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/serialization/jsonvalue/JsonValueUnitTest.java
deleted file mode 100644
index 465daf13f5..0000000000
--- a/jackson/src/test/java/com/baeldung/jackson/serialization/jsonvalue/JsonValueUnitTest.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.baeldung.jackson.serialization.jsonvalue;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Source code github.com/readlearncode
- *
- * @author Alex Theedom www.readlearncode.com
- * @version 1.0
- */
-public class JsonValueUnitTest {
-
- @Test
- public void whenSerializingUsingJsonValue_thenCorrect() throws JsonProcessingException {
-
- // act
- String result = new ObjectMapper().writeValueAsString(Course.Level.ADVANCED);
-
- // assert
- assertThat(result).isEqualTo("\"Advanced\"");
-
- }
-}
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/test/JacksonAnnotationUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/test/JacksonAnnotationUnitTest.java
index 935777bad1..ee11f8f20e 100644
--- a/jackson/src/test/java/com/baeldung/jackson/test/JacksonAnnotationUnitTest.java
+++ b/jackson/src/test/java/com/baeldung/jackson/test/JacksonAnnotationUnitTest.java
@@ -14,6 +14,7 @@ import java.util.TimeZone;
import org.junit.Test;
+import com.baeldung.jackson.annotation.AliasBean;
import com.baeldung.jackson.annotation.BeanWithCreator;
import com.baeldung.jackson.annotation.BeanWithCustomAnnotation;
import com.baeldung.jackson.annotation.BeanWithFilter;
@@ -36,6 +37,7 @@ import com.baeldung.jackson.date.EventWithSerializer;
import com.baeldung.jackson.dtos.MyMixInForIgnoreType;
import com.baeldung.jackson.dtos.withEnum.DistanceEnumWithValue;
import com.baeldung.jackson.exception.UserWithRoot;
+import com.baeldung.jackson.exception.UserWithRootNamespace;
import com.baeldung.jackson.jsonview.Item;
import com.baeldung.jackson.jsonview.Views;
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -46,6 +48,7 @@ import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.ser.FilterProvider;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
+import com.fasterxml.jackson.dataformat.xml.XmlMapper;
public class JacksonAnnotationUnitTest {
@@ -372,5 +375,45 @@ public class JacksonAnnotationUnitTest {
assertThat(result, containsString("1"));
assertThat(result, containsString("name"));
}
+
+ @Test
+ public void whenDeserializingUsingJsonAlias_thenCorrect() throws IOException {
+
+ // arrange
+ String json = "{\"fName\": \"John\", \"lastName\": \"Green\"}";
+
+ // act
+ AliasBean aliasBean = new ObjectMapper().readerFor(AliasBean.class).readValue(json);
+
+ // assert
+ assertThat(aliasBean.getFirstName(), is("John"));
+ }
+
+ @Test
+ public void whenSerializingUsingXMLRootNameWithNameSpace_thenCorrect() throws JsonProcessingException {
+
+ // arrange
+ UserWithRootNamespace author = new UserWithRootNamespace(1, "John");
+
+ // act
+ ObjectMapper mapper = new XmlMapper();
+ mapper = mapper.enable(SerializationFeature.WRAP_ROOT_VALUE).enable(SerializationFeature.INDENT_OUTPUT);
+ String result = mapper.writeValueAsString(author);
+
+ // assert
+ assertThat(result, containsString(""));
+
+ /*
+
+ 3006b44a-cf62-4cfe-b3d8-30dc6c46ea96
+ 1
+ John
+
+
+ */
+
+ }
+
+
}
diff --git a/jackson/src/test/java/com/baeldung/jackson/xml/XMLSerializeDeserializeUnitTest.java b/jackson/src/test/java/com/baeldung/jackson/xml/XMLSerializeDeserializeUnitTest.java
index 039edd45bc..1d430e9758 100644
--- a/jackson/src/test/java/com/baeldung/jackson/xml/XMLSerializeDeserializeUnitTest.java
+++ b/jackson/src/test/java/com/baeldung/jackson/xml/XMLSerializeDeserializeUnitTest.java
@@ -2,8 +2,10 @@ package com.baeldung.jackson.xml;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -56,17 +58,14 @@ public class XMLSerializeDeserializeUnitTest {
@Test
public void whenJavaGotFromXmlStrWithCapitalElem_thenCorrect() throws IOException {
XmlMapper xmlMapper = new XmlMapper();
- SimpleBeanForCapitalizedFields value = xmlMapper.
- readValue("1 2 ",
- SimpleBeanForCapitalizedFields.class);
+ SimpleBeanForCapitalizedFields value = xmlMapper.readValue("1 2 ", SimpleBeanForCapitalizedFields.class);
assertTrue(value.getX() == 1 && value.getY() == 2);
}
@Test
public void whenJavaSerializedToXmlFileWithCapitalizedField_thenCorrect() throws IOException {
XmlMapper xmlMapper = new XmlMapper();
- xmlMapper.writeValue(new File("target/simple_bean_capitalized.xml"),
- new SimpleBeanForCapitalizedFields());
+ xmlMapper.writeValue(new File("target/simple_bean_capitalized.xml"), new SimpleBeanForCapitalizedFields());
File file = new File("target/simple_bean_capitalized.xml");
assertNotNull(file);
}
@@ -74,7 +73,9 @@ public class XMLSerializeDeserializeUnitTest {
@Test
public void whenJavaDeserializedFromXmlFile_thenCorrect() throws IOException {
XmlMapper xmlMapper = new XmlMapper();
- Person value = xmlMapper.readValue(new File("src/test/resources/person.xml"), Person.class);
+
+ String xml = "Rohan Daye 9911034731 9911033478 1 Name1 City1 2 Name2 City2 ";
+ Person value = xmlMapper.readValue(xml, Person.class);
assertTrue(value.getAddress()
.get(0)
@@ -90,33 +91,38 @@ public class XMLSerializeDeserializeUnitTest {
public void whenJavaSerializedToXmlFile_thenSuccess() throws IOException {
XmlMapper xmlMapper = new XmlMapper();
+ String expectedXml = "Rohan Daye 9911034731 9911033478 1 Name1 City1 2 Name2 City2 ";
+
Person person = new Person();
person.setFirstName("Rohan");
person.setLastName("Daye");
List ph = new ArrayList<>();
- ph.add("9911778981");
- ph.add("9991111111");
+ ph.add("9911034731");
+ ph.add("9911033478");
person.setPhoneNumbers(ph);
List addresses = new ArrayList<>();
-
+
Address address1 = new Address();
address1.setStreetNumber("1");
- address1.setStreetName("streetname1");
- address1.setCity("city1");
-
+ address1.setStreetName("Name1");
+ address1.setCity("City1");
+
Address address2 = new Address();
address2.setStreetNumber("2");
- address2.setStreetName("streetname2");
- address2.setCity("city2");
-
+ address2.setStreetName("Name2");
+ address2.setCity("City2");
+
addresses.add(address1);
addresses.add(address2);
+
person.setAddress(addresses);
- xmlMapper.writeValue(new File("src/test/resources/PersonGenerated.xml"), person);
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ xmlMapper.writeValue(byteArrayOutputStream, person);
+ assertEquals(expectedXml, byteArrayOutputStream.toString());
}
private static String inputStreamToString(InputStream is) throws IOException {
diff --git a/jackson/src/test/resources/PersonGenerated.xml b/jackson/src/test/resources/PersonGenerated.xml
deleted file mode 100644
index 6ebadd971a..0000000000
--- a/jackson/src/test/resources/PersonGenerated.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
- 9911778981
- 9991111111
-
-
- 1
- streetname1
- city1
-
-
- 2
- streetname2
- city2
-
-
-
\ No newline at end of file
diff --git a/jackson/src/test/resources/person.xml b/jackson/src/test/resources/person.xml
deleted file mode 100644
index 39a6e859c4..0000000000
--- a/jackson/src/test/resources/person.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
- Rohan
- Daye
- 9911034731
- 9911033478
-
-
- 1
- Name1
- City1
-
-
- 2
- Name2
- City2
-
-
-
\ No newline at end of file
diff --git a/java-collections-maps-2/pom.xml b/java-collections-maps-2/pom.xml
new file mode 100644
index 0000000000..4ab94a7ae3
--- /dev/null
+++ b/java-collections-maps-2/pom.xml
@@ -0,0 +1,48 @@
+
+
+ 4.0.0
+ java-collections-maps-2
+ 0.1.0-SNAPSHOT
+ java-collections-maps-2
+ jar
+
+
+ com.baeldung
+ parent-java
+ 0.0.1-SNAPSHOT
+ ../parent-java
+
+
+
+
+ org.eclipse.collections
+ eclipse-collections
+ ${eclipse-collections.version}
+
+
+ net.sf.trove4j
+ trove4j
+ ${trove4j.version}
+
+
+ it.unimi.dsi
+ fastutil
+ ${fastutil.version}
+
+
+ colt
+ colt
+ ${colt.version}
+
+
+
+
+ 8.2.0
+ 3.0.2
+ 8.1.0
+ 1.2.0
+
+
+
\ No newline at end of file
diff --git a/java-collections-maps-2/src/main/java/com/baeldung/map/PrimitiveMaps.java b/java-collections-maps-2/src/main/java/com/baeldung/map/PrimitiveMaps.java
new file mode 100644
index 0000000000..d835950c68
--- /dev/null
+++ b/java-collections-maps-2/src/main/java/com/baeldung/map/PrimitiveMaps.java
@@ -0,0 +1,69 @@
+package com.baeldung.map;
+
+import cern.colt.map.AbstractIntDoubleMap;
+import cern.colt.map.OpenIntDoubleHashMap;
+import gnu.trove.map.TDoubleIntMap;
+import gnu.trove.map.hash.TDoubleIntHashMap;
+import it.unimi.dsi.fastutil.ints.Int2BooleanMap;
+import it.unimi.dsi.fastutil.ints.Int2BooleanOpenHashMap;
+import it.unimi.dsi.fastutil.ints.Int2BooleanSortedMap;
+import it.unimi.dsi.fastutil.ints.Int2BooleanSortedMaps;
+import org.eclipse.collections.api.map.primitive.ImmutableIntIntMap;
+import org.eclipse.collections.api.map.primitive.MutableIntIntMap;
+import org.eclipse.collections.api.map.primitive.MutableObjectDoubleMap;
+import org.eclipse.collections.impl.factory.primitive.IntIntMaps;
+import org.eclipse.collections.impl.factory.primitive.ObjectDoubleMaps;
+
+public class PrimitiveMaps {
+
+ public static void main(String[] args) {
+
+ eclipseCollectionsMap();
+ troveMap();
+ coltMap();
+ fastutilMap();
+ }
+
+ private static void fastutilMap() {
+ Int2BooleanMap int2BooleanMap = new Int2BooleanOpenHashMap();
+ int2BooleanMap.put(1, true);
+ int2BooleanMap.put(7, false);
+ int2BooleanMap.put(4, true);
+
+ boolean value = int2BooleanMap.get(1);
+
+ Int2BooleanSortedMap int2BooleanSorted = Int2BooleanSortedMaps.EMPTY_MAP;
+ }
+
+ private static void coltMap() {
+ AbstractIntDoubleMap map = new OpenIntDoubleHashMap();
+ map.put(1, 4.5);
+ double value = map.get(1);
+ }
+
+ private static void eclipseCollectionsMap() {
+ MutableIntIntMap mutableIntIntMap = IntIntMaps.mutable.empty();
+ mutableIntIntMap.addToValue(1, 1);
+
+ ImmutableIntIntMap immutableIntIntMap = IntIntMaps.immutable.empty();
+
+ MutableObjectDoubleMap dObject = ObjectDoubleMaps.mutable.empty();
+ dObject.addToValue("price", 150.5);
+ dObject.addToValue("quality", 4.4);
+ dObject.addToValue("stability", 0.8);
+ }
+
+ private static void troveMap() {
+ double[] doubles = new double[] {1.2, 4.5, 0.3};
+ int[] ints = new int[] {1, 4, 0};
+
+ TDoubleIntMap doubleIntMap = new TDoubleIntHashMap(doubles, ints);
+
+ doubleIntMap.put(1.2, 22);
+ doubleIntMap.put(4.5, 16);
+
+ doubleIntMap.adjustValue(1.2, 1);
+ doubleIntMap.adjustValue(4.5, 4);
+ doubleIntMap.adjustValue(0.3, 7);
+ }
+}
diff --git a/java-collections-maps/README.md b/java-collections-maps/README.md
index 5d65e961de..2eeb2c8843 100644
--- a/java-collections-maps/README.md
+++ b/java-collections-maps/README.md
@@ -20,3 +20,4 @@
- [Comparing Two HashMaps in Java](https://www.baeldung.com/java-compare-hashmaps)
- [Immutable Map Implementations in Java](https://www.baeldung.com/java-immutable-maps)
- [Map to String Conversion in Java](https://www.baeldung.com/java-map-to-string-conversion)
+- [Guide to Apache Commons MultiValuedMap](https://www.baeldung.com/apache-commons-multi-valued-map)
diff --git a/java-dates-2/.gitignore b/java-dates-2/.gitignore
new file mode 100644
index 0000000000..6471aabbcf
--- /dev/null
+++ b/java-dates-2/.gitignore
@@ -0,0 +1,29 @@
+*.class
+
+0.*
+
+#folders#
+/target
+/neoDb*
+/data
+/src/main/webapp/WEB-INF/classes
+*/META-INF/*
+.resourceCache
+
+# Packaged files #
+*.jar
+*.war
+*.ear
+
+# Files generated by integration tests
+*.txt
+backup-pom.xml
+/bin/
+/temp
+
+#IntelliJ specific
+.idea/
+*.iml
+
+#jenv
+.java-version
\ No newline at end of file
diff --git a/java-dates-2/pom.xml b/java-dates-2/pom.xml
new file mode 100644
index 0000000000..c2464ed47f
--- /dev/null
+++ b/java-dates-2/pom.xml
@@ -0,0 +1,55 @@
+
+ 4.0.0
+ com.baeldung
+ java-dates-2
+ 0.1.0-SNAPSHOT
+ jar
+ java-dates-2
+
+
+ com.baeldung
+ parent-java
+ 0.0.1-SNAPSHOT
+ ../parent-java
+
+
+
+
+
+ org.assertj
+ assertj-core
+ ${assertj.version}
+ test
+
+
+
+
+ java-dates-2
+
+
+ src/main/resources
+ true
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven-compiler-plugin.version}
+
+ ${maven.compiler.source}
+ ${maven.compiler.target}
+
+
+
+
+
+
+
+ 3.6.1
+ 1.9
+ 1.9
+
+
diff --git a/java-dates-2/src/test/java/com/baeldung/xmlgregoriancalendar/XmlGregorianCalendarConverterUnitTest.java b/java-dates-2/src/test/java/com/baeldung/xmlgregoriancalendar/XmlGregorianCalendarConverterUnitTest.java
new file mode 100644
index 0000000000..b221c04199
--- /dev/null
+++ b/java-dates-2/src/test/java/com/baeldung/xmlgregoriancalendar/XmlGregorianCalendarConverterUnitTest.java
@@ -0,0 +1,36 @@
+package com.baeldung.xmlgregoriancalendar;
+
+import org.junit.Test;
+
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeConstants;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.XMLGregorianCalendar;
+import java.time.LocalDate;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class XmlGregorianCalendarConverterUnitTest {
+
+ @Test
+ public void fromLocalDateToXMLGregorianCalendar() throws DatatypeConfigurationException {
+ LocalDate localDate = LocalDate.of(2017, 4, 25);
+ XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(localDate.toString());
+
+ assertThat(xmlGregorianCalendar.getYear()).isEqualTo(localDate.getYear());
+ assertThat(xmlGregorianCalendar.getMonth()).isEqualTo(localDate.getMonthValue());
+ assertThat(xmlGregorianCalendar.getDay()).isEqualTo(localDate.getDayOfMonth());
+ assertThat(xmlGregorianCalendar.getTimezone()).isEqualTo(DatatypeConstants.FIELD_UNDEFINED);
+ }
+
+ @Test
+ public void fromXMLGregorianCalendarToLocalDate() throws DatatypeConfigurationException {
+ XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar("2017-04-25");
+ LocalDate localDate = LocalDate.of(xmlGregorianCalendar.getYear(), xmlGregorianCalendar.getMonth(), xmlGregorianCalendar.getDay());
+
+ assertThat(localDate.getYear()).isEqualTo(xmlGregorianCalendar.getYear());
+ assertThat(localDate.getMonthValue()).isEqualTo(xmlGregorianCalendar.getMonth());
+ assertThat(localDate.getDayOfMonth()).isEqualTo(xmlGregorianCalendar.getDay());
+ }
+
+}
diff --git a/java-dates/pom.xml b/java-dates/pom.xml
index 8dd5ad675e..d4f690d894 100644
--- a/java-dates/pom.xml
+++ b/java-dates/pom.xml
@@ -76,7 +76,6 @@
3.5
- 1.16.12
2.10
3.6.1
diff --git a/java-ee-8-security-api/pom.xml b/java-ee-8-security-api/pom.xml
index ad33c74ad3..0cce84e5f2 100644
--- a/java-ee-8-security-api/pom.xml
+++ b/java-ee-8-security-api/pom.xml
@@ -58,6 +58,13 @@
+
+ app-auth-basic-store-db
+ app-auth-form-store-ldap
+ app-auth-custom-form-store-custom
+ app-auth-custom-no-store
+
+
9080
9443
@@ -70,11 +77,4 @@
3.2.2
-
- app-auth-basic-store-db
- app-auth-form-store-ldap
- app-auth-custom-form-store-custom
- app-auth-custom-no-store
-
-
diff --git a/java-lite/pom.xml b/java-lite/pom.xml
index b261e521a1..ce6e838d92 100644
--- a/java-lite/pom.xml
+++ b/java-lite/pom.xml
@@ -95,7 +95,6 @@
1.15
5.1.45
1.7.0
- 2.9.7
1.15
diff --git a/java-math/.gitignore b/java-math/.gitignore
new file mode 100644
index 0000000000..30b2b7442c
--- /dev/null
+++ b/java-math/.gitignore
@@ -0,0 +1,4 @@
+/target/
+.settings/
+.classpath
+.project
\ No newline at end of file
diff --git a/java-math/README.md b/java-math/README.md
new file mode 100644
index 0000000000..d821348204
--- /dev/null
+++ b/java-math/README.md
@@ -0,0 +1,10 @@
+## Relevant articles:
+
+- [Calculate Factorial in Java](https://www.baeldung.com/java-calculate-factorial)
+- [Generate Combinations in Java](https://www.baeldung.com/java-combinations-algorithm)
+- [Check If Two Rectangles Overlap In Java](https://www.baeldung.com/java-check-if-two-rectangles-overlap)
+- [Calculate the Distance Between Two Points in Java](https://www.baeldung.com/java-distance-between-two-points)
+- [Find the Intersection of Two Lines in Java](https://www.baeldung.com/java-intersection-of-two-lines)
+- [Round Up to the Nearest Hundred](https://www.baeldung.com/java-round-up-nearest-hundred)
+- [Calculate Percentage in Java](https://www.baeldung.com/java-calculate-percentage)
+- [Convert Latitude and Longitude to a 2D Point in Java](https://www.baeldung.com/java-convert-latitude-longitude)
\ No newline at end of file
diff --git a/java-math/pom.xml b/java-math/pom.xml
new file mode 100644
index 0000000000..159d053df3
--- /dev/null
+++ b/java-math/pom.xml
@@ -0,0 +1,68 @@
+
+ 4.0.0
+ java-math
+ 0.0.1-SNAPSHOT
+ java-math
+
+
+ com.baeldung
+ parent-modules
+ 1.0.0-SNAPSHOT
+
+
+
+
+ org.apache.commons
+ commons-math3
+ ${commons-math3.version}
+
+
+ com.google.guava
+ guava
+ ${guava.version}
+
+
+ commons-codec
+ commons-codec
+ ${commons-codec.version}
+
+
+ org.projectlombok
+ lombok
+ ${lombok.version}
+ provided
+
+
+ org.assertj
+ assertj-core
+ ${org.assertj.core.version}
+ test
+
+
+ com.github.dpaukov
+ combinatoricslib3
+ 3.3.0
+
+
+
+
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ ${exec-maven-plugin.version}
+
+
+
+
+
+
+ 3.6.1
+ 3.9.0
+ 1.11
+ 27.0.1-jre
+
+
+
\ No newline at end of file
diff --git a/java-math/src/main/java/com/baeldung/algorithms/combination/ApacheCommonsCombinationGenerator.java b/java-math/src/main/java/com/baeldung/algorithms/combination/ApacheCommonsCombinationGenerator.java
new file mode 100644
index 0000000000..40142ce940
--- /dev/null
+++ b/java-math/src/main/java/com/baeldung/algorithms/combination/ApacheCommonsCombinationGenerator.java
@@ -0,0 +1,29 @@
+package com.baeldung.algorithms.combination;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.commons.math3.util.CombinatoricsUtils;
+
+public class ApacheCommonsCombinationGenerator {
+
+ private static final int N = 6;
+ private static final int R = 3;
+
+ /**
+ * Print all combinations of r elements from a set
+ * @param n - number of elements in set
+ * @param r - number of elements in selection
+ */
+ public static void generate(int n, int r) {
+ Iterator iterator = CombinatoricsUtils.combinationsIterator(n, r);
+ while (iterator.hasNext()) {
+ final int[] combination = iterator.next();
+ System.out.println(Arrays.toString(combination));
+ }
+ }
+
+ public static void main(String[] args) {
+ generate(N, R);
+ }
+}
\ No newline at end of file
diff --git a/java-math/src/main/java/com/baeldung/algorithms/combination/CombinatoricsLibCombinationGenerator.java b/java-math/src/main/java/com/baeldung/algorithms/combination/CombinatoricsLibCombinationGenerator.java
new file mode 100644
index 0000000000..0afdeefb8b
--- /dev/null
+++ b/java-math/src/main/java/com/baeldung/algorithms/combination/CombinatoricsLibCombinationGenerator.java
@@ -0,0 +1,13 @@
+package com.baeldung.algorithms.combination;
+
+import org.paukov.combinatorics3.Generator;
+
+public class CombinatoricsLibCombinationGenerator {
+
+ public static void main(String[] args) {
+ Generator.combination(0, 1, 2, 3, 4, 5)
+ .simple(3)
+ .stream()
+ .forEach(System.out::println);
+ }
+}
diff --git a/java-math/src/main/java/com/baeldung/algorithms/combination/GuavaCombinationsGenerator.java b/java-math/src/main/java/com/baeldung/algorithms/combination/GuavaCombinationsGenerator.java
new file mode 100644
index 0000000000..d2783881ba
--- /dev/null
+++ b/java-math/src/main/java/com/baeldung/algorithms/combination/GuavaCombinationsGenerator.java
@@ -0,0 +1,17 @@
+package com.baeldung.algorithms.combination;
+
+import java.util.Arrays;
+import java.util.Set;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
+
+public class GuavaCombinationsGenerator {
+
+ public static void main(String[] args) {
+
+ Set> combinations = Sets.combinations(ImmutableSet.of(0, 1, 2, 3, 4, 5), 3);
+ System.out.println(combinations.size());
+ System.out.println(Arrays.toString(combinations.toArray()));
+ }
+}
diff --git a/java-math/src/main/java/com/baeldung/algorithms/combination/IterativeCombinationGenerator.java b/java-math/src/main/java/com/baeldung/algorithms/combination/IterativeCombinationGenerator.java
new file mode 100644
index 0000000000..676d2f41e3
--- /dev/null
+++ b/java-math/src/main/java/com/baeldung/algorithms/combination/IterativeCombinationGenerator.java
@@ -0,0 +1,52 @@
+package com.baeldung.algorithms.combination;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class IterativeCombinationGenerator {
+
+ private static final int N = 5;
+ private static final int R = 2;
+
+ /**
+ * Generate all combinations of r elements from a set
+ * @param n the number of elements in input set
+ * @param r the number of elements in a combination
+ * @return the list containing all combinations
+ */
+ public List generate(int n, int r) {
+ List combinations = new ArrayList<>();
+ int[] combination = new int[r];
+
+ // initialize with lowest lexicographic combination
+ for (int i = 0; i < r; i++) {
+ combination[i] = i;
+ }
+
+ while (combination[r - 1] < n) {
+ combinations.add(combination.clone());
+
+ // generate next combination in lexicographic order
+ int t = r - 1;
+ while (t != 0 && combination[t] == n - r + t) {
+ t--;
+ }
+ combination[t]++;
+ for (int i = t + 1; i < r; i++) {
+ combination[i] = combination[i - 1] + 1;
+ }
+ }
+
+ return combinations;
+ }
+
+ public static void main(String[] args) {
+ IterativeCombinationGenerator generator = new IterativeCombinationGenerator();
+ List combinations = generator.generate(N, R);
+ System.out.println(combinations.size());
+ for (int[] combination : combinations) {
+ System.out.println(Arrays.toString(combination));
+ }
+ }
+}
diff --git a/java-math/src/main/java/com/baeldung/algorithms/combination/SelectionRecursiveCombinationGenerator.java b/java-math/src/main/java/com/baeldung/algorithms/combination/SelectionRecursiveCombinationGenerator.java
new file mode 100644
index 0000000000..52305b8c2f
--- /dev/null
+++ b/java-math/src/main/java/com/baeldung/algorithms/combination/SelectionRecursiveCombinationGenerator.java
@@ -0,0 +1,53 @@
+package com.baeldung.algorithms.combination;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class SelectionRecursiveCombinationGenerator {
+
+ private static final int N = 6;
+ private static final int R = 3;
+
+ /**
+ * Generate all combinations of r elements from a set
+ * @param n - number of elements in input set
+ * @param r - number of elements to be chosen
+ * @return the list containing all combinations
+ */
+ public List generate(int n, int r) {
+ List combinations = new ArrayList<>();
+ helper(combinations, new int[r], 0, n - 1, 0);
+ return combinations;
+ }
+
+ /**
+ * Choose elements from set by recursing over elements selected
+ * @param combinations - List to store generated combinations
+ * @param data - current combination
+ * @param start - starting element of remaining set
+ * @param end - last element of remaining set
+ * @param index - number of elements chosen so far.
+ */
+ private void helper(List combinations, int data[], int start, int end, int index) {
+ if (index == data.length) {
+ int[] combination = data.clone();
+ combinations.add(combination);
+ } else {
+ int max = Math.min(end, end + 1 - data.length + index);
+ for (int i = start; i <= max; i++) {
+ data[index] = i;
+ helper(combinations, data, i + 1, end, index + 1);
+ }
+ }
+ }
+
+ public static void main(String[] args) {
+ SelectionRecursiveCombinationGenerator generator = new SelectionRecursiveCombinationGenerator();
+ List combinations = generator.generate(N, R);
+ for (int[] combination : combinations) {
+ System.out.println(Arrays.toString(combination));
+ }
+ System.out.printf("generated %d combinations of %d items from %d ", combinations.size(), R, N);
+ }
+}
diff --git a/java-math/src/main/java/com/baeldung/algorithms/combination/SetRecursiveCombinationGenerator.java b/java-math/src/main/java/com/baeldung/algorithms/combination/SetRecursiveCombinationGenerator.java
new file mode 100644
index 0000000000..a73447b31d
--- /dev/null
+++ b/java-math/src/main/java/com/baeldung/algorithms/combination/SetRecursiveCombinationGenerator.java
@@ -0,0 +1,50 @@
+package com.baeldung.algorithms.combination;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class SetRecursiveCombinationGenerator {
+
+ private static final int N = 5;
+ private static final int R = 2;
+
+ /**
+ * Generate all combinations of r elements from a set
+ * @param n - number of elements in set
+ * @param r - number of elements in selection
+ * @return the list containing all combinations
+ */
+ public List generate(int n, int r) {
+ List combinations = new ArrayList<>();
+ helper(combinations, new int[r], 0, n-1, 0);
+ return combinations;
+ }
+
+ /**
+ * @param combinations - List to contain the generated combinations
+ * @param data - List of elements in the selection
+ * @param start - index of the starting element in the remaining set
+ * @param end - index of the last element in the set
+ * @param index - number of elements selected so far
+ */
+ private void helper(List combinations, int data[], int start, int end, int index) {
+ if (index == data.length) {
+ int[] combination = data.clone();
+ combinations.add(combination);
+ } else if (start <= end) {
+ data[index] = start;
+ helper(combinations, data, start + 1, end, index + 1);
+ helper(combinations, data, start + 1, end, index);
+ }
+ }
+
+ public static void main(String[] args) {
+ SetRecursiveCombinationGenerator generator = new SetRecursiveCombinationGenerator();
+ List combinations = generator.generate(N, R);
+ for (int[] combination : combinations) {
+ System.out.println(Arrays.toString(combination));
+ }
+ System.out.printf("generated %d combinations of %d items from %d ", combinations.size(), R, N);
+ }
+}
diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsService.java b/java-math/src/main/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsService.java
similarity index 100%
rename from algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsService.java
rename to java-math/src/main/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsService.java
diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/factorial/Factorial.java b/java-math/src/main/java/com/baeldung/algorithms/factorial/Factorial.java
similarity index 100%
rename from algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/factorial/Factorial.java
rename to java-math/src/main/java/com/baeldung/algorithms/factorial/Factorial.java
diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/linesintersection/LinesIntersectionService.java b/java-math/src/main/java/com/baeldung/algorithms/linesintersection/LinesIntersectionService.java
similarity index 100%
rename from algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/linesintersection/LinesIntersectionService.java
rename to java-math/src/main/java/com/baeldung/algorithms/linesintersection/LinesIntersectionService.java
diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/EllipticalMercator.java b/java-math/src/main/java/com/baeldung/algorithms/mercator/EllipticalMercator.java
similarity index 100%
rename from algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/EllipticalMercator.java
rename to java-math/src/main/java/com/baeldung/algorithms/mercator/EllipticalMercator.java
diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/Mercator.java b/java-math/src/main/java/com/baeldung/algorithms/mercator/Mercator.java
similarity index 100%
rename from algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/Mercator.java
rename to java-math/src/main/java/com/baeldung/algorithms/mercator/Mercator.java
diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/SphericalMercator.java b/java-math/src/main/java/com/baeldung/algorithms/mercator/SphericalMercator.java
similarity index 100%
rename from algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/SphericalMercator.java
rename to java-math/src/main/java/com/baeldung/algorithms/mercator/SphericalMercator.java
diff --git a/java-numbers/src/main/java/com/baeldung/percentage/PercentageCalculator.java b/java-math/src/main/java/com/baeldung/algorithms/percentage/PercentageCalculator.java
similarity index 93%
rename from java-numbers/src/main/java/com/baeldung/percentage/PercentageCalculator.java
rename to java-math/src/main/java/com/baeldung/algorithms/percentage/PercentageCalculator.java
index e74de2cc67..f69b23146e 100644
--- a/java-numbers/src/main/java/com/baeldung/percentage/PercentageCalculator.java
+++ b/java-math/src/main/java/com/baeldung/algorithms/percentage/PercentageCalculator.java
@@ -1,4 +1,4 @@
-package com.baeldung.percentage;
+package com.baeldung.algorithms.percentage;
import java.util.Scanner;
diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Point.java b/java-math/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Point.java
similarity index 100%
rename from algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Point.java
rename to java-math/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Point.java
diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Rectangle.java b/java-math/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Rectangle.java
similarity index 100%
rename from algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Rectangle.java
rename to java-math/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Rectangle.java
diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/roundedup/RoundUpToHundred.java b/java-math/src/main/java/com/baeldung/algorithms/roundedup/RoundUpToHundred.java
similarity index 100%
rename from algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/roundedup/RoundUpToHundred.java
rename to java-math/src/main/java/com/baeldung/algorithms/roundedup/RoundUpToHundred.java
diff --git a/java-math/src/main/resources/logback.xml b/java-math/src/main/resources/logback.xml
new file mode 100644
index 0000000000..7d900d8ea8
--- /dev/null
+++ b/java-math/src/main/resources/logback.xml
@@ -0,0 +1,13 @@
+
+
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/java-math/src/test/java/com/baeldung/algorithms/combination/CombinationUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/combination/CombinationUnitTest.java
new file mode 100644
index 0000000000..987b6ddae6
--- /dev/null
+++ b/java-math/src/test/java/com/baeldung/algorithms/combination/CombinationUnitTest.java
@@ -0,0 +1,35 @@
+package com.baeldung.algorithms.combination;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.List;
+
+import org.junit.Test;
+
+public class CombinationUnitTest {
+
+ private static final int N = 5;
+ private static final int R = 3;
+ private static final int nCr = 10;
+
+ @Test
+ public void givenSetAndSelectionSize_whenCalculatedUsingSetRecursiveAlgorithm_thenExpectedCount() {
+ SetRecursiveCombinationGenerator generator = new SetRecursiveCombinationGenerator();
+ List selection = generator.generate(N, R);
+ assertEquals(nCr, selection.size());
+ }
+
+ @Test
+ public void givenSetAndSelectionSize_whenCalculatedUsingSelectionRecursiveAlgorithm_thenExpectedCount() {
+ SelectionRecursiveCombinationGenerator generator = new SelectionRecursiveCombinationGenerator();
+ List selection = generator.generate(N, R);
+ assertEquals(nCr, selection.size());
+ }
+
+ @Test
+ public void givenSetAndSelectionSize_whenCalculatedUsingIterativeAlgorithm_thenExpectedCount() {
+ IterativeCombinationGenerator generator = new IterativeCombinationGenerator();
+ List selection = generator.generate(N, R);
+ assertEquals(nCr, selection.size());
+ }
+}
diff --git a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsServiceUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsServiceUnitTest.java
similarity index 93%
rename from algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsServiceUnitTest.java
rename to java-math/src/test/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsServiceUnitTest.java
index 785afdbb2b..784681a807 100644
--- a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsServiceUnitTest.java
+++ b/java-math/src/test/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsServiceUnitTest.java
@@ -2,8 +2,6 @@ package com.baeldung.algorithms.distancebetweenpoints;
import org.junit.Test;
-import com.baeldung.algorithms.distancebetweenpoints.DistanceBetweenPointsService;
-
import static org.junit.Assert.assertEquals;
public class DistanceBetweenPointsServiceUnitTest {
diff --git a/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/factorial/FactorialUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/factorial/FactorialUnitTest.java
similarity index 100%
rename from algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/factorial/FactorialUnitTest.java
rename to java-math/src/test/java/com/baeldung/algorithms/factorial/FactorialUnitTest.java
diff --git a/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/linesintersection/LinesIntersectionServiceUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/linesintersection/LinesIntersectionServiceUnitTest.java
similarity index 100%
rename from algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/linesintersection/LinesIntersectionServiceUnitTest.java
rename to java-math/src/test/java/com/baeldung/algorithms/linesintersection/LinesIntersectionServiceUnitTest.java
diff --git a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/mercator/EllipticalMercatorUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/mercator/EllipticalMercatorUnitTest.java
similarity index 100%
rename from algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/mercator/EllipticalMercatorUnitTest.java
rename to java-math/src/test/java/com/baeldung/algorithms/mercator/EllipticalMercatorUnitTest.java
diff --git a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/mercator/SphericalMercatorUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/mercator/SphericalMercatorUnitTest.java
similarity index 100%
rename from algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/mercator/SphericalMercatorUnitTest.java
rename to java-math/src/test/java/com/baeldung/algorithms/mercator/SphericalMercatorUnitTest.java
diff --git a/java-numbers/src/test/java/com/baeldung/percentage/PercentageCalculatorUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/percentage/PercentageCalculatorUnitTest.java
similarity index 95%
rename from java-numbers/src/test/java/com/baeldung/percentage/PercentageCalculatorUnitTest.java
rename to java-math/src/test/java/com/baeldung/algorithms/percentage/PercentageCalculatorUnitTest.java
index 202d4f8112..e49acc0c4b 100644
--- a/java-numbers/src/test/java/com/baeldung/percentage/PercentageCalculatorUnitTest.java
+++ b/java-math/src/test/java/com/baeldung/algorithms/percentage/PercentageCalculatorUnitTest.java
@@ -1,4 +1,4 @@
-package com.baeldung.percentage;
+package com.baeldung.algorithms.percentage;
import org.junit.Assert;
import org.junit.Test;
diff --git a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/rectanglesoverlap/RectangleUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/rectanglesoverlap/RectangleUnitTest.java
similarity index 93%
rename from algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/rectanglesoverlap/RectangleUnitTest.java
rename to java-math/src/test/java/com/baeldung/algorithms/rectanglesoverlap/RectangleUnitTest.java
index 6707b34477..e4bb614b48 100644
--- a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/rectanglesoverlap/RectangleUnitTest.java
+++ b/java-math/src/test/java/com/baeldung/algorithms/rectanglesoverlap/RectangleUnitTest.java
@@ -4,9 +4,6 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import org.junit.Test;
-import com.baeldung.algorithms.rectanglesoverlap.Point;
-import com.baeldung.algorithms.rectanglesoverlap.Rectangle;
-
public class RectangleUnitTest {
@Test
diff --git a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/roundedup/RoundUpToHundredUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/roundedup/RoundUpToHundredUnitTest.java
similarity index 100%
rename from algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/roundedup/RoundUpToHundredUnitTest.java
rename to java-math/src/test/java/com/baeldung/algorithms/roundedup/RoundUpToHundredUnitTest.java
diff --git a/java-streams-2/README.md b/java-streams-2/README.md
new file mode 100644
index 0000000000..83ef97686f
--- /dev/null
+++ b/java-streams-2/README.md
@@ -0,0 +1,3 @@
+### Relevant Articles:
+- [Guide to Stream.reduce()](https://www.baeldung.com/java-stream-reduce)
+
diff --git a/java-streams-2/pom.xml b/java-streams-2/pom.xml
new file mode 100644
index 0000000000..5004249352
--- /dev/null
+++ b/java-streams-2/pom.xml
@@ -0,0 +1,50 @@
+
+
+ 4.0.0
+ com.baeldung.javastreams2
+ javastreams2
+ 1.0
+ Stream Reduce
+ jar
+
+
+ com.baeldung
+ parent-java
+ 0.0.1-SNAPSHOT
+ ../parent-java
+
+
+
+
+ org.openjdk.jmh
+ jmh-core
+ ${jmh.version}
+
+
+ org.openjdk.jmh
+ jmh-generator-annprocess
+ ${jmh.version}
+
+
+ junit
+ junit
+ ${junit.version}
+ test
+ jar
+
+
+ org.assertj
+ assertj-core
+ ${assertj.version}
+ test
+
+
+
+
+ UTF-8
+ 1.8
+ 1.8
+ 1.21
+ 3.11.1
+
+
\ No newline at end of file
diff --git a/java-streams-2/src/main/java/com/baeldung/reduce/application/Application.java b/java-streams-2/src/main/java/com/baeldung/reduce/application/Application.java
new file mode 100644
index 0000000000..79c557524d
--- /dev/null
+++ b/java-streams-2/src/main/java/com/baeldung/reduce/application/Application.java
@@ -0,0 +1,39 @@
+package com.baeldung.reduce.application;
+
+import com.baeldung.reduce.entities.User;
+import com.baeldung.reduce.utilities.NumberUtils;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class Application {
+
+ public static void main(String[] args) {
+ List numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
+ int result1 = numbers.stream().reduce(0, (subtotal, element) -> subtotal + element);
+ System.out.println(result1);
+
+ int result2 = numbers.stream().reduce(0, Integer::sum);
+ System.out.println(result2);
+
+ List letters = Arrays.asList("a", "b", "c", "d", "e");
+ String result3 = letters.stream().reduce("", (partialString, element) -> partialString + element);
+ System.out.println(result3);
+
+ String result4 = letters.stream().reduce("", String::concat);
+ System.out.println(result4);
+
+ String result5 = letters.stream().reduce("", (partialString, element) -> partialString.toUpperCase() + element.toUpperCase());
+ System.out.println(result5);
+
+ List users = Arrays.asList(new User("John", 30), new User("Julie", 35));
+ int result6 = users.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
+ System.out.println(result6);
+
+ String result7 = letters.parallelStream().reduce("", String::concat);
+ System.out.println(result7);
+
+ int result8 = users.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
+ System.out.println(result8);
+ }
+}
diff --git a/java-streams-2/src/main/java/com/baeldung/reduce/benchmarks/JMHStreamReduceBenchMark.java b/java-streams-2/src/main/java/com/baeldung/reduce/benchmarks/JMHStreamReduceBenchMark.java
new file mode 100644
index 0000000000..af4a9276a9
--- /dev/null
+++ b/java-streams-2/src/main/java/com/baeldung/reduce/benchmarks/JMHStreamReduceBenchMark.java
@@ -0,0 +1,52 @@
+package com.baeldung.reduce.benchmarks;
+
+import com.baeldung.reduce.entities.User;
+import java.util.ArrayList;
+import java.util.List;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+@State(Scope.Thread)
+@BenchmarkMode(Mode.AverageTime)
+public class JMHStreamReduceBenchMark {
+
+ private final List userList = createUsers();
+
+ public static void main(String[] args) throws RunnerException {
+
+ Options options = new OptionsBuilder()
+ .include(JMHStreamReduceBenchMark.class.getSimpleName()).threads(1)
+ .forks(1).shouldFailOnError(true).shouldDoGC(true)
+ .jvmArgs("-server").build();
+ new Runner(options).run();
+ }
+
+ private List createUsers() {
+ List users = new ArrayList<>();
+ for (int i = 0; i <= 1000000; i++) {
+ users.add(new User("John" + i, i));
+ }
+ return users;
+ }
+
+ @Benchmark
+ public Integer executeReduceOnParallelizedStream() {
+ return this.userList
+ .parallelStream()
+ .reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
+ }
+
+ @Benchmark
+ public Integer executeReduceOnSequentialStream() {
+ return this.userList
+ .stream()
+ .reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
+ }
+}
diff --git a/java-streams-2/src/main/java/com/baeldung/reduce/entities/User.java b/java-streams-2/src/main/java/com/baeldung/reduce/entities/User.java
new file mode 100644
index 0000000000..a17c6a02b6
--- /dev/null
+++ b/java-streams-2/src/main/java/com/baeldung/reduce/entities/User.java
@@ -0,0 +1,25 @@
+package com.baeldung.reduce.entities;
+
+public class User {
+
+ private final String name;
+ private final int age;
+
+ public User(String name, int age) {
+ this.name = name;
+ this.age = age;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ @Override
+ public String toString() {
+ return "User{" + "name=" + name + ", age=" + age + '}';
+ }
+}
diff --git a/java-streams-2/src/main/java/com/baeldung/reduce/utilities/NumberUtils.java b/java-streams-2/src/main/java/com/baeldung/reduce/utilities/NumberUtils.java
new file mode 100644
index 0000000000..a7a4b8df29
--- /dev/null
+++ b/java-streams-2/src/main/java/com/baeldung/reduce/utilities/NumberUtils.java
@@ -0,0 +1,52 @@
+package com.baeldung.reduce.utilities;
+
+import java.util.List;
+import java.util.function.BiFunction;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public abstract class NumberUtils {
+
+ private static final Logger LOGGER = Logger.getLogger(NumberUtils.class.getName());
+
+ public static int divideListElements(List values, Integer divider) {
+ return values.stream()
+ .reduce(0, (a, b) -> {
+ try {
+ return a / divider + b / divider;
+ } catch (ArithmeticException e) {
+ LOGGER.log(Level.INFO, "Arithmetic Exception: Division by Zero");
+ }
+ return 0;
+ });
+ }
+
+ public static int divideListElementsWithExtractedTryCatchBlock(List values, int divider) {
+ return values.stream().reduce(0, (a, b) -> divide(a, divider) + divide(b, divider));
+ }
+
+ public static int divideListElementsWithApplyFunctionMethod(List values, int divider) {
+ BiFunction division = (a, b) -> a / b;
+ return values.stream().reduce(0, (a, b) -> applyFunction(division, a, divider) + applyFunction(division, b, divider));
+ }
+
+ private static int divide(int value, int factor) {
+ int result = 0;
+ try {
+ result = value / factor;
+ } catch (ArithmeticException e) {
+ LOGGER.log(Level.INFO, "Arithmetic Exception: Division by Zero");
+ }
+ return result;
+ }
+
+ private static int applyFunction(BiFunction function, int a, int b) {
+ try {
+ return function.apply(a, b);
+ }
+ catch(Exception e) {
+ LOGGER.log(Level.INFO, "Exception thrown!");
+ }
+ return 0;
+ }
+}
diff --git a/java-streams-2/src/test/java/com/baeldung/reduce/tests/StreamReduceUnitTest.java b/java-streams-2/src/test/java/com/baeldung/reduce/tests/StreamReduceUnitTest.java
new file mode 100644
index 0000000000..564d614017
--- /dev/null
+++ b/java-streams-2/src/test/java/com/baeldung/reduce/tests/StreamReduceUnitTest.java
@@ -0,0 +1,79 @@
+package com.baeldung.reduce.tests;
+
+import com.baeldung.reduce.entities.User;
+import com.baeldung.reduce.utilities.NumberUtils;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.Test;
+
+public class StreamReduceUnitTest {
+
+ @Test
+ public void givenIntegerList_whenReduceWithSumAccumulatorLambda_thenCorrect() {
+ List numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
+ int result = numbers.stream().reduce(0, (subtotal, element) -> subtotal + element);
+ assertThat(result).isEqualTo(21);
+ }
+
+ @Test
+ public void givenIntegerList_whenReduceWithSumAccumulatorMethodReference_thenCorrect() {
+ List numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
+ int result = numbers.stream().reduce(0, Integer::sum);
+ assertThat(result).isEqualTo(21);
+ }
+
+ @Test
+ public void givenStringList_whenReduceWithConcatenatorAccumulatorLambda_thenCorrect() {
+ List letters = Arrays.asList("a", "b", "c", "d", "e");
+ String result = letters.stream().reduce("", (partialString, element) -> partialString + element);
+ assertThat(result).isEqualTo("abcde");
+ }
+
+ @Test
+ public void givenStringList_whenReduceWithConcatenatorAccumulatorMethodReference_thenCorrect() {
+ List letters = Arrays.asList("a", "b", "c", "d", "e");
+ String result = letters.stream().reduce("", String::concat);
+ assertThat(result).isEqualTo("abcde");
+ }
+
+ @Test
+ public void givenStringList_whenReduceWithUppercaseConcatenatorAccumulator_thenCorrect() {
+ List letters = Arrays.asList("a", "b", "c", "d", "e");
+ String result = letters.stream().reduce("", (partialString, element) -> partialString.toUpperCase() + element.toUpperCase());
+ assertThat(result).isEqualTo("ABCDE");
+ }
+
+ @Test
+ public void givenUserList_whenReduceWithAgeAccumulatorAndSumCombiner_thenCorrect() {
+ List users = Arrays.asList(new User("John", 30), new User("Julie", 35));
+ int result = users.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
+ assertThat(result).isEqualTo(65);
+ }
+
+ @Test
+ public void givenStringList_whenReduceWithParallelStream_thenCorrect() {
+ List letters = Arrays.asList("a", "b", "c", "d", "e");
+ String result = letters.parallelStream().reduce("", String::concat);
+ assertThat(result).isEqualTo("abcde");
+ }
+
+ @Test
+ public void givenNumberUtilsClass_whenCalledDivideListElements_thenCorrect() {
+ List numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
+ assertThat(NumberUtils.divideListElements(numbers, 1)).isEqualTo(21);
+ }
+
+ @Test
+ public void givenNumberUtilsClass_whenCalledDivideListElementsWithExtractedTryCatchBlock_thenCorrect() {
+ List numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
+ assertThat(NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 1)).isEqualTo(21);
+ }
+
+ @Test
+ public void givenStream_whneCalleddivideListElementsWithApplyFunctionMethod_thenCorrect() {
+ List numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
+ assertThat(NumberUtils.divideListElementsWithApplyFunctionMethod(numbers, 1)).isEqualTo(21);
+ }
+}
diff --git a/java-streams/README.md b/java-streams/README.md
index 15ea1c742a..e294e5aee1 100644
--- a/java-streams/README.md
+++ b/java-streams/README.md
@@ -3,7 +3,7 @@
## Java Streams Cookbooks and Examples
### Relevant Articles:
-- [Java 8 Streams Advanced](http://www.baeldung.com/java-8-streams)
+- [The Java 8 Stream API Tutorial](http://www.baeldung.com/java-8-streams)
- [Introduction to Java 8 Streams](http://www.baeldung.com/java-8-streams-introduction)
- [Java 8 and Infinite Streams](http://www.baeldung.com/java-inifinite-streams)
- [Java 8 Stream findFirst() vs. findAny()](http://www.baeldung.com/java-stream-findfirst-vs-findany)
@@ -17,3 +17,4 @@
- [Java Stream Filter with Lambda Expression](https://www.baeldung.com/java-stream-filter-lambda)
- [Counting Matches on a Stream Filter](https://www.baeldung.com/java-stream-filter-count)
- [Java 8 Streams peek() API](https://www.baeldung.com/java-streams-peek-api)
+- [Working With Maps Using Streams](https://www.baeldung.com/java-maps-streams)
diff --git a/java-streams/pom.xml b/java-streams/pom.xml
index 0de1a424d6..00384eeead 100644
--- a/java-streams/pom.xml
+++ b/java-streams/pom.xml
@@ -108,7 +108,6 @@
1.21
3.5
- 1.16.12
0.9.0
1.15
0.6.5
diff --git a/java-streams/src/main/java/com/baeldung/reduce/application/Application.java b/java-streams/src/main/java/com/baeldung/reduce/application/Application.java
new file mode 100644
index 0000000000..b101c86780
--- /dev/null
+++ b/java-streams/src/main/java/com/baeldung/reduce/application/Application.java
@@ -0,0 +1,70 @@
+package com.baeldung.reduce.application;
+
+import com.baeldung.reduce.entities.User;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.Warmup;
+
+public class Application {
+
+ public static void main(String[] args) throws Exception {
+ List numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
+ int result1 = numbers.stream().reduce(0, (subtotal, element) -> subtotal + element);
+ System.out.println(result1);
+
+ int result2 = numbers.stream().reduce(0, Integer::sum);
+ System.out.println(result2);
+
+ List letters = Arrays.asList("a", "b", "c", "d", "e");
+ String result3 = letters.stream().reduce("", (partialString, element) -> partialString + element);
+ System.out.println(result3);
+
+ String result4 = letters.stream().reduce("", String::concat);
+ System.out.println(result4);
+
+ String result5 = letters.stream().reduce("", (partialString, element) -> partialString.toUpperCase() + element.toUpperCase());
+ System.out.println(result5);
+
+ List users = Arrays.asList(new User("John", 30), new User("Julie", 35));
+ int result6 = users.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
+ System.out.println(result6);
+
+ String result7 = letters.parallelStream().reduce("", String::concat);
+ System.out.println(result7);
+
+ int result8 = users.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
+ System.out.println(result8);
+
+ org.openjdk.jmh.Main.main(args);
+
+ }
+
+ @Benchmark
+ @Fork(value = 1, warmups = 2)
+ @Warmup(iterations = 2)
+ @BenchmarkMode(Mode.AverageTime)
+ public void executeReduceOnParallelizedStream() {
+ List userList = new ArrayList<>();
+ for (int i = 0; i <= 1000000; i++) {
+ userList.add(new User("John" + i, i));
+ }
+ userList.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
+ }
+
+ @Benchmark
+ @Fork(value = 1, warmups = 2)
+ @Warmup(iterations = 2)
+ @BenchmarkMode(Mode.AverageTime)
+ public void executeReduceOnSequentialStream() {
+ List userList = new ArrayList<>();
+ for (int i = 0; i <= 1000000; i++) {
+ userList.add(new User("John" + i, i));
+ }
+ userList.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
+ }
+}
diff --git a/java-streams/src/main/java/com/baeldung/reduce/entities/User.java b/java-streams/src/main/java/com/baeldung/reduce/entities/User.java
new file mode 100644
index 0000000000..a17c6a02b6
--- /dev/null
+++ b/java-streams/src/main/java/com/baeldung/reduce/entities/User.java
@@ -0,0 +1,25 @@
+package com.baeldung.reduce.entities;
+
+public class User {
+
+ private final String name;
+ private final int age;
+
+ public User(String name, int age) {
+ this.name = name;
+ this.age = age;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ @Override
+ public String toString() {
+ return "User{" + "name=" + name + ", age=" + age + '}';
+ }
+}
diff --git a/java-streams/src/main/java/com/baeldung/reduce/utilities/NumberUtils.java b/java-streams/src/main/java/com/baeldung/reduce/utilities/NumberUtils.java
new file mode 100644
index 0000000000..8b4af2cbe2
--- /dev/null
+++ b/java-streams/src/main/java/com/baeldung/reduce/utilities/NumberUtils.java
@@ -0,0 +1,52 @@
+package com.baeldung.reduce.utilities;
+
+import java.util.List;
+import java.util.function.BiFunction;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public abstract class NumberUtils {
+
+ private static final Logger LOGGER = Logger.getLogger(NumberUtils.class.getName());
+
+ public static int divideListElements(List values, Integer divider) {
+ return values.stream()
+ .reduce(0, (a, b) -> {
+ try {
+ return a / divider + b / divider;
+ } catch (ArithmeticException e) {
+ LOGGER.log(Level.INFO, "Arithmetic Exception: Division by Zero");
+ }
+ return 0;
+ });
+ }
+
+ public static int divideListElementsWithExtractedTryCatchBlock(List values, int divider) {
+ return values.stream().reduce(0, (a, b) -> divide(a, divider) + divide(b, divider));
+ }
+
+ public static int divideListElementsWithApplyFunctionMethod(List values, int divider) {
+ BiFunction division = (a, b) -> a / b;
+ return values.stream().reduce(0, (a, b) -> applyFunction(division, a, divider) + applyFunction(division, b, divider));
+ }
+
+ private static int divide(int value, int factor) {
+ int result = 0;
+ try {
+ result = value / factor;
+ } catch (ArithmeticException e) {
+ LOGGER.log(Level.INFO, "Arithmetic Exception: Division by Zero");
+ }
+ return result;
+ }
+
+ private static int applyFunction(BiFunction function, int a, int b) {
+ try {
+ return function.apply(a, b);
+ }
+ catch(Exception e) {
+ LOGGER.log(Level.INFO, "Exception occurred!");
+ }
+ return 0;
+ }
+}
diff --git a/java-streams/src/test/java/com/baeldung/reduce/tests/StreamReduceUnitTest.java b/java-streams/src/test/java/com/baeldung/reduce/tests/StreamReduceUnitTest.java
new file mode 100644
index 0000000000..8e2ff7bf22
--- /dev/null
+++ b/java-streams/src/test/java/com/baeldung/reduce/tests/StreamReduceUnitTest.java
@@ -0,0 +1,79 @@
+package com.baeldung.reduce.tests;
+
+import com.baeldung.reduce.entities.User;
+import com.baeldung.reduce.utilities.NumberUtils;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.Test;
+
+public class StreamReduceUnitTest {
+
+ @Test
+ public void givenIntegerList_whenReduceWithSumAccumulatorLambda_thenCorrect() {
+ List numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
+ int result = numbers.stream().reduce(0, (a, b) -> a + b);
+ assertThat(result).isEqualTo(21);
+ }
+
+ @Test
+ public void givenIntegerList_whenReduceWithSumAccumulatorMethodReference_thenCorrect() {
+ List numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
+ int result = numbers.stream().reduce(0, Integer::sum);
+ assertThat(result).isEqualTo(21);
+ }
+
+ @Test
+ public void givenStringList_whenReduceWithConcatenatorAccumulatorLambda_thenCorrect() {
+ List letters = Arrays.asList("a", "b", "c", "d", "e");
+ String result = letters.stream().reduce("", (a, b) -> a + b);
+ assertThat(result).isEqualTo("abcde");
+ }
+
+ @Test
+ public void givenStringList_whenReduceWithConcatenatorAccumulatorMethodReference_thenCorrect() {
+ List letters = Arrays.asList("a", "b", "c", "d", "e");
+ String result = letters.stream().reduce("", String::concat);
+ assertThat(result).isEqualTo("abcde");
+ }
+
+ @Test
+ public void givenStringList_whenReduceWithUppercaseConcatenatorAccumulator_thenCorrect() {
+ List letters = Arrays.asList("a", "b", "c", "d", "e");
+ String result = letters.stream().reduce("", (a, b) -> a.toUpperCase() + b.toUpperCase());
+ assertThat(result).isEqualTo("ABCDE");
+ }
+
+ @Test
+ public void givenUserList_whenReduceWithAgeAccumulatorAndSumCombiner_thenCorrect() {
+ List users = Arrays.asList(new User("John", 30), new User("Julie", 35));
+ int result = users.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
+ assertThat(result).isEqualTo(65);
+ }
+
+ @Test
+ public void givenStringList_whenReduceWithParallelStream_thenCorrect() {
+ List letters = Arrays.asList("a", "b", "c", "d", "e");
+ String result = letters.parallelStream().reduce("", String::concat);
+ assertThat(result).isEqualTo("abcde");
+ }
+
+ @Test
+ public void givenNumberUtilsClass_whenCalledDivideListElements_thenCorrect() {
+ List numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
+ assertThat(NumberUtils.divideListElements(numbers, 1)).isEqualTo(21);
+ }
+
+ @Test
+ public void givenNumberUtilsClass_whenCalledDivideListElementsWithExtractedTryCatchBlock_thenCorrect() {
+ List numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
+ assertThat(NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 1)).isEqualTo(21);
+ }
+
+ @Test
+ public void givenStream_whneCalleddivideListElementsWithApplyFunctionMethod_thenCorrect() {
+ List numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
+ assertThat(NumberUtils.divideListElementsWithApplyFunctionMethod(numbers, 1)).isEqualTo(21);
+ }
+}
diff --git a/java-strings/README.md b/java-strings/README.md
index 1ab5e098f6..b342f53918 100644
--- a/java-strings/README.md
+++ b/java-strings/README.md
@@ -22,7 +22,7 @@
- [Check if a String is a Palindrome](http://www.baeldung.com/java-palindrome)
- [Comparing Strings in Java](http://www.baeldung.com/java-compare-strings)
- [Check If a String Is Numeric in Java](http://www.baeldung.com/java-check-string-number)
-- [Why Use char[] Array Over a String for Storing Passwords in Java?](http://www.baeldung.com/java-storing-passwords)
+- [Use char[] Array Over a String for Manipulating Passwords in Java?](http://www.baeldung.com/java-storing-passwords)
- [Convert a String to Title Case](http://www.baeldung.com/java-string-title-case)
- [Compact Strings in Java 9](http://www.baeldung.com/java-9-compact-string)
- [Java Check a String for Lowercase/Uppercase Letter, Special Character and Digit](https://www.baeldung.com/java-lowercase-uppercase-special-character-digit-regex)
@@ -53,3 +53,4 @@
- [Java String Interview Questions and Answers](https://www.baeldung.com/java-string-interview-questions)
- [Check if a String is a Pangram in Java](https://www.baeldung.com/java-string-pangram)
- [Check If a String Contains Multiple Keywords](https://www.baeldung.com/string-contains-multiple-words)
+- [Common String Operations in Java](https://www.baeldung.com/java-string-operations)
diff --git a/javaxval/pom.xml b/javaxval/pom.xml
index f31aa0dc77..7ecddc0ca8 100644
--- a/javaxval/pom.xml
+++ b/javaxval/pom.xml
@@ -55,8 +55,7 @@