Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>cxf-introduction</artifactId>
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>apache-cxf</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<properties>
|
||||
<cxf.version>3.1.6</cxf.version>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<mainClass>com.baeldung.cxf.introduction.Server</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.19.1</version>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/StudentTest.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-frontend-jaxws</artifactId>
|
||||
<version>${cxf.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-transports-http-jetty</artifactId>
|
||||
<version>${cxf.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.baeldung.cxf.introduction;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.jws.WebService;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
|
||||
@WebService
|
||||
public interface Baeldung {
|
||||
public String hello(String name);
|
||||
|
||||
public String helloStudent(Student student);
|
||||
|
||||
@XmlJavaTypeAdapter(StudentMapAdapter.class)
|
||||
public Map<Integer, Student> getStudents();
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.cxf.introduction;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.jws.WebService;
|
||||
|
||||
@WebService(endpointInterface = "com.baeldung.cxf.introduction.Baeldung")
|
||||
public class BaeldungImpl implements Baeldung {
|
||||
private Map<Integer, Student> students = new LinkedHashMap<Integer, Student>();
|
||||
|
||||
public String hello(String name) {
|
||||
return "Hello " + name;
|
||||
}
|
||||
|
||||
public String helloStudent(Student student) {
|
||||
students.put(students.size() + 1, student);
|
||||
return "Hello " + student.getName();
|
||||
}
|
||||
|
||||
public Map<Integer, Student> getStudents() {
|
||||
return students;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.cxf.introduction;
|
||||
|
||||
import javax.xml.ws.Endpoint;
|
||||
|
||||
public class Server {
|
||||
public static void main(String args[]) throws InterruptedException {
|
||||
BaeldungImpl implementor = new BaeldungImpl();
|
||||
String address = "http://localhost:8080/baeldung";
|
||||
Endpoint.publish(address, implementor);
|
||||
System.out.println("Server ready...");
|
||||
Thread.sleep(60 * 1000);
|
||||
System.out.println("Server exiting");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.baeldung.cxf.introduction;
|
||||
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
|
||||
@XmlJavaTypeAdapter(StudentAdapter.class)
|
||||
public interface Student {
|
||||
public String getName();
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.baeldung.cxf.introduction;
|
||||
|
||||
import javax.xml.bind.annotation.adapters.XmlAdapter;
|
||||
|
||||
public class StudentAdapter extends XmlAdapter<StudentImpl, Student> {
|
||||
public StudentImpl marshal(Student student) throws Exception {
|
||||
if (student instanceof StudentImpl) {
|
||||
return (StudentImpl) student;
|
||||
}
|
||||
return new StudentImpl(student.getName());
|
||||
}
|
||||
|
||||
public Student unmarshal(StudentImpl student) throws Exception {
|
||||
return student;
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.cxf.introduction;
|
||||
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
@XmlType(name = "Student")
|
||||
public class StudentImpl implements Student {
|
||||
private String name;
|
||||
|
||||
StudentImpl() {
|
||||
}
|
||||
|
||||
public StudentImpl(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.baeldung.cxf.introduction;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
@XmlType(name = "StudentMap")
|
||||
public class StudentMap {
|
||||
private List<StudentEntry> entries = new ArrayList<StudentEntry>();
|
||||
|
||||
@XmlElement(nillable = false, name = "entry")
|
||||
public List<StudentEntry> getEntries() {
|
||||
return entries;
|
||||
}
|
||||
|
||||
@XmlType(name = "StudentEntry")
|
||||
public static class StudentEntry {
|
||||
private Integer id;
|
||||
private Student student;
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setStudent(Student student) {
|
||||
this.student = student;
|
||||
}
|
||||
|
||||
public Student getStudent() {
|
||||
return student;
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.baeldung.cxf.introduction;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.annotation.adapters.XmlAdapter;
|
||||
|
||||
public class StudentMapAdapter extends XmlAdapter<StudentMap, Map<Integer, Student>> {
|
||||
public StudentMap marshal(Map<Integer, Student> boundMap) throws Exception {
|
||||
StudentMap valueMap = new StudentMap();
|
||||
for (Map.Entry<Integer, Student> boundEntry : boundMap.entrySet()) {
|
||||
StudentMap.StudentEntry valueEntry = new StudentMap.StudentEntry();
|
||||
valueEntry.setStudent(boundEntry.getValue());
|
||||
valueEntry.setId(boundEntry.getKey());
|
||||
valueMap.getEntries().add(valueEntry);
|
||||
}
|
||||
return valueMap;
|
||||
}
|
||||
|
||||
public Map<Integer, Student> unmarshal(StudentMap valueMap) throws Exception {
|
||||
Map<Integer, Student> boundMap = new LinkedHashMap<Integer, Student>();
|
||||
for (StudentMap.StudentEntry studentEntry : valueMap.getEntries()) {
|
||||
boundMap.put(studentEntry.getId(), studentEntry.getStudent());
|
||||
}
|
||||
return boundMap;
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
package com.baeldung.cxf.introduction;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.ws.Service;
|
||||
import javax.xml.ws.soap.SOAPBinding;
|
||||
|
||||
import com.baeldung.cxf.introduction.Baeldung;
|
||||
import com.baeldung.cxf.introduction.Student;
|
||||
import com.baeldung.cxf.introduction.StudentImpl;
|
||||
|
||||
public class StudentTest {
|
||||
private static QName SERVICE_NAME = new QName("http://introduction.cxf.baeldung.com/", "Baeldung");
|
||||
private static QName PORT_NAME = new QName("http://introduction.cxf.baeldung.com/", "BaeldungPort");
|
||||
|
||||
private Service service;
|
||||
private Baeldung baeldungProxy;
|
||||
private BaeldungImpl baeldungImpl;
|
||||
|
||||
{
|
||||
service = Service.create(SERVICE_NAME);
|
||||
String endpointAddress = "http://localhost:8080/baeldung";
|
||||
service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void reinstantiateBaeldungInstances() {
|
||||
baeldungImpl = new BaeldungImpl();
|
||||
baeldungProxy = service.getPort(PORT_NAME, Baeldung.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingHelloMethod_thenCorrect() {
|
||||
String endpointResponse = baeldungProxy.hello("Baeldung");
|
||||
String localResponse = baeldungImpl.hello("Baeldung");
|
||||
assertEquals(localResponse, endpointResponse);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingHelloStudentMethod_thenCorrect() {
|
||||
Student student = new StudentImpl("John Doe");
|
||||
String endpointResponse = baeldungProxy.helloStudent(student);
|
||||
String localResponse = baeldungImpl.helloStudent(student);
|
||||
assertEquals(localResponse, endpointResponse);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usingGetStudentsMethod_thenCorrect() {
|
||||
Student student1 = new StudentImpl("Adam");
|
||||
baeldungProxy.helloStudent(student1);
|
||||
|
||||
Student student2 = new StudentImpl("Eve");
|
||||
baeldungProxy.helloStudent(student2);
|
||||
|
||||
Map<Integer, Student> students = baeldungProxy.getStudents();
|
||||
assertEquals("Adam", students.get(1).getName());
|
||||
assertEquals("Eve", students.get(2).getName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>apache-cxf</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>cxf-introduction</module>
|
||||
</modules>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<defaultGoal>install</defaultGoal>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.5.0</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</project>
|
||||
+12
-1
@@ -9,17 +9,28 @@
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>19.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>3.4.1</version>
|
||||
<version>3.5.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-guava</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -14,9 +14,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
import static org.assertj.core.api.Assertions.withPrecision;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
public class AssertJCoreTest {
|
||||
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
package com.baeldung.assertj.introduction;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.HashBasedTable;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Multimaps;
|
||||
import com.google.common.collect.Range;
|
||||
import com.google.common.collect.Table;
|
||||
import com.google.common.collect.TreeRangeMap;
|
||||
import com.google.common.io.Files;
|
||||
import org.assertj.guava.data.MapEntry;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import static org.assertj.guava.api.Assertions.assertThat;
|
||||
import static org.assertj.guava.api.Assertions.entry;
|
||||
|
||||
public class AssertJGuavaTest {
|
||||
|
||||
@Test
|
||||
public void givenTwoEmptyFiles_whenComparingContent_thenEqual() throws Exception {
|
||||
final File temp1 = File.createTempFile("bael", "dung1");
|
||||
final File temp2 = File.createTempFile("bael", "dung2");
|
||||
|
||||
assertThat(Files.asByteSource(temp1))
|
||||
.hasSize(0)
|
||||
.hasSameContentAs(Files.asByteSource(temp2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenMultimap_whenVerifying_thenCorrect() throws Exception {
|
||||
final Multimap<Integer, String> mmap = ArrayListMultimap.create();
|
||||
mmap.put(1, "one");
|
||||
mmap.put(1, "1");
|
||||
|
||||
assertThat(mmap)
|
||||
.hasSize(2)
|
||||
.containsKeys(1)
|
||||
.contains(entry(1, "one"))
|
||||
.contains(entry(1, "1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenMultimaps_whenVerifyingContent_thenCorrect() throws Exception {
|
||||
final Multimap<Integer, String> mmap1 = ArrayListMultimap.create();
|
||||
mmap1.put(1, "one");
|
||||
mmap1.put(1, "1");
|
||||
mmap1.put(2, "two");
|
||||
mmap1.put(2, "2");
|
||||
|
||||
final Multimap<Integer, String> mmap1_clone = Multimaps.newSetMultimap(new HashMap<>(), HashSet::new);
|
||||
mmap1_clone.put(1, "one");
|
||||
mmap1_clone.put(1, "1");
|
||||
mmap1_clone.put(2, "two");
|
||||
mmap1_clone.put(2, "2");
|
||||
|
||||
final Multimap<Integer, String> mmap2 = Multimaps.newSetMultimap(new HashMap<>(), HashSet::new);
|
||||
mmap2.put(1, "one");
|
||||
mmap2.put(1, "1");
|
||||
|
||||
assertThat(mmap1)
|
||||
.containsAllEntriesOf(mmap2)
|
||||
.containsAllEntriesOf(mmap1_clone)
|
||||
.hasSameEntriesAs(mmap1_clone);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenOptional_whenVerifyingContent_thenShouldBeEqual() throws Exception {
|
||||
final Optional<String> something = Optional.of("something");
|
||||
|
||||
assertThat(something)
|
||||
.isPresent()
|
||||
.extractingValue()
|
||||
.isEqualTo("something");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenRange_whenVerifying_thenShouldBeCorrect() throws Exception {
|
||||
final Range<String> range = Range.openClosed("a", "g");
|
||||
|
||||
assertThat(range)
|
||||
.hasOpenedLowerBound()
|
||||
.isNotEmpty()
|
||||
.hasClosedUpperBound()
|
||||
.contains("b");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenRangeMap_whenVerifying_thenShouldBeCorrect() throws Exception {
|
||||
final TreeRangeMap<Integer, String> map = TreeRangeMap.create();
|
||||
|
||||
map.put(Range.closed(0, 60), "F");
|
||||
map.put(Range.closed(61, 70), "D");
|
||||
|
||||
assertThat(map)
|
||||
.isNotEmpty()
|
||||
.containsKeys(0)
|
||||
.contains(MapEntry.entry(34, "F"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTable_whenVerifying_thenShouldBeCorrect() throws Exception {
|
||||
final Table<Integer, String, String> table = HashBasedTable.create(2, 2);
|
||||
|
||||
table.put(1, "A", "PRESENT");
|
||||
table.put(1, "B", "ABSENT");
|
||||
|
||||
assertThat(table)
|
||||
.hasRowCount(1)
|
||||
.containsValues("ABSENT")
|
||||
.containsCell(1, "B", "ABSENT");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package com.baeldung.assertj.introduction;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static java.time.LocalDate.ofYearDay;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class AssertJJava8Test {
|
||||
|
||||
@Test
|
||||
public void givenOptional_shouldAssert() throws Exception {
|
||||
final Optional<String> givenOptional = Optional.of("something");
|
||||
|
||||
assertThat(givenOptional)
|
||||
.isPresent()
|
||||
.hasValue("something");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenPredicate_shouldAssert() throws Exception {
|
||||
final Predicate<String> predicate = s -> s.length() > 4;
|
||||
|
||||
assertThat(predicate)
|
||||
.accepts("aaaaa", "bbbbb")
|
||||
.rejects("a", "b")
|
||||
.acceptsAll(asList("aaaaa", "bbbbb"))
|
||||
.rejectsAll(asList("a", "b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenLocalDate_shouldAssert() throws Exception {
|
||||
final LocalDate givenLocalDate = LocalDate.of(2016, 7, 8);
|
||||
final LocalDate todayDate = LocalDate.now();
|
||||
|
||||
assertThat(givenLocalDate)
|
||||
.isBefore(LocalDate.of(2020, 7, 8))
|
||||
.isAfterOrEqualTo(LocalDate.of(1989, 7, 8));
|
||||
|
||||
assertThat(todayDate)
|
||||
.isAfter(LocalDate.of(1989, 7, 8))
|
||||
.isToday();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenLocalDateTime_shouldAssert() throws Exception {
|
||||
final LocalDateTime givenLocalDate = LocalDateTime.of(2016, 7, 8, 12, 0);
|
||||
|
||||
assertThat(givenLocalDate)
|
||||
.isBefore(LocalDateTime.of(2020, 7, 8, 11, 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenLocalTime_shouldAssert() throws Exception {
|
||||
final LocalTime givenLocalTime = LocalTime.of(12, 15);
|
||||
|
||||
assertThat(givenLocalTime)
|
||||
.isAfter(LocalTime.of(1, 0))
|
||||
.hasSameHourAs(LocalTime.of(12, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenList_shouldAssertFlatExtracting() throws Exception {
|
||||
final List<LocalDate> givenList = asList(ofYearDay(2016, 5), ofYearDay(2015, 6));
|
||||
|
||||
assertThat(givenList)
|
||||
.flatExtracting(LocalDate::getYear)
|
||||
.contains(2015);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenList_shouldAssertFlatExtractingLeapYear() throws Exception {
|
||||
final List<LocalDate> givenList = asList(ofYearDay(2016, 5), ofYearDay(2015, 6));
|
||||
|
||||
assertThat(givenList)
|
||||
.flatExtracting(LocalDate::isLeapYear)
|
||||
.contains(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenList_shouldAssertFlatExtractingClass() throws Exception {
|
||||
final List<LocalDate> givenList = asList(ofYearDay(2016, 5), ofYearDay(2015, 6));
|
||||
|
||||
assertThat(givenList)
|
||||
.flatExtracting(Object::getClass)
|
||||
.contains(LocalDate.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenList_shouldAssertMultipleFlatExtracting() throws Exception {
|
||||
final List<LocalDate> givenList = asList(ofYearDay(2016, 5), ofYearDay(2015, 6));
|
||||
|
||||
assertThat(givenList)
|
||||
.flatExtracting(LocalDate::getYear, LocalDate::getDayOfMonth)
|
||||
.contains(2015, 6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_shouldSatisfy() throws Exception {
|
||||
final String givenString = "someString";
|
||||
|
||||
assertThat(givenString)
|
||||
.satisfies(s -> {
|
||||
assertThat(s).isNotEmpty();
|
||||
assertThat(s).hasSize(10);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_shouldMatch() throws Exception {
|
||||
final String emptyString = "";
|
||||
|
||||
assertThat(emptyString)
|
||||
.matches(String::isEmpty);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenList_shouldHasOnlyOneElementSatisfying() throws Exception {
|
||||
final List<String> givenList = Arrays.asList("");
|
||||
|
||||
assertThat(givenList)
|
||||
.hasOnlyOneElementSatisfying(s -> assertThat(s).isEmpty());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.baeldung.hamcrest;
|
||||
|
||||
public class Animal {
|
||||
String name;
|
||||
boolean wild;
|
||||
String sound;
|
||||
|
||||
public Animal(String name, boolean wild, String sound) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.wild = wild;
|
||||
this.sound = sound;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public boolean isWild() {
|
||||
return wild;
|
||||
}
|
||||
public void setWild(boolean wild) {
|
||||
this.wild = wild;
|
||||
}
|
||||
public String getSound() {
|
||||
return sound;
|
||||
}
|
||||
public void setSound(String sound) {
|
||||
this.sound = sound;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.baeldung.hamcrest;
|
||||
|
||||
public class Cat extends Animal {
|
||||
|
||||
public Cat() {
|
||||
super("cat", false, "meow");
|
||||
}
|
||||
|
||||
public String makeSound() {
|
||||
return getSound();
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,24 @@
|
||||
package org.baeldung.hamcrest;
|
||||
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Factory;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.TypeSafeMatcher;
|
||||
|
||||
public class IsPositiveInteger extends TypeSafeMatcher<Integer> {
|
||||
|
||||
public void describeTo(Description description) {
|
||||
description.appendText("a positive integer");
|
||||
}
|
||||
|
||||
@Factory
|
||||
public static Matcher<Integer> isAPositiveInteger() {
|
||||
return new IsPositiveInteger();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean matchesSafely(Integer integer) {
|
||||
return integer > 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.baeldung.hamcrest;
|
||||
|
||||
public class Person {
|
||||
String name;
|
||||
String address;
|
||||
|
||||
public Person(String personName, String personAddress) {
|
||||
name = personName;
|
||||
address = personAddress;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String str="[address:"+address+",name:"+name+"]";
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -170,6 +170,39 @@
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>net.alchim31.maven</groupId>
|
||||
<artifactId>yuicompressor-maven-plugin</artifactId>
|
||||
<version>1.5.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compress</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<nosuffix>true</nosuffix>
|
||||
<webappDirectory>${project.build.directory}/min</webappDirectory>
|
||||
<excludes>
|
||||
<exclude>**/*.min.js</exclude>
|
||||
<exclude>**/handlebars-3133af2.js</exclude>
|
||||
<exclude>**/require.js</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<configuration>
|
||||
<webResources>
|
||||
<resource>
|
||||
<directory>${project.build.directory}/min</directory>
|
||||
</resource>
|
||||
</webResources>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
window.Todos = Ember.Application.create();
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,54 @@
|
||||
package com.baeldung.jackson.dtos;
|
||||
|
||||
public class MyDtoWithSpecialField {
|
||||
|
||||
private String[] stringValue;
|
||||
private int intValue;
|
||||
private boolean booleanValue;
|
||||
|
||||
public MyDtoWithSpecialField() {
|
||||
super();
|
||||
}
|
||||
|
||||
public MyDtoWithSpecialField(final String[] stringValue, final int intValue, final boolean booleanValue) {
|
||||
super();
|
||||
|
||||
this.stringValue = stringValue;
|
||||
this.intValue = intValue;
|
||||
this.booleanValue = booleanValue;
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
public String[] getStringValue() {
|
||||
return stringValue;
|
||||
}
|
||||
|
||||
public void setStringValue(final String[] stringValue) {
|
||||
this.stringValue = stringValue;
|
||||
}
|
||||
|
||||
public int getIntValue() {
|
||||
return intValue;
|
||||
}
|
||||
|
||||
public void setIntValue(final int intValue) {
|
||||
this.intValue = intValue;
|
||||
}
|
||||
|
||||
public boolean isBooleanValue() {
|
||||
return booleanValue;
|
||||
}
|
||||
|
||||
public void setBooleanValue(final boolean booleanValue) {
|
||||
this.booleanValue = booleanValue;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MyDto [stringValue=" + stringValue + ", intValue=" + intValue + ", booleanValue=" + booleanValue + "]";
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -3,6 +3,6 @@ package com.baeldung.jackson.dtos;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreType;
|
||||
|
||||
@JsonIgnoreType
|
||||
public class MyMixInForString {
|
||||
public class MyMixInForIgnoreType {
|
||||
//
|
||||
}
|
||||
@@ -12,11 +12,8 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import com.baeldung.jackson.bidirection.ItemWithIdentity;
|
||||
import com.baeldung.jackson.bidirection.ItemWithRef;
|
||||
import com.baeldung.jackson.bidirection.UserWithRef;
|
||||
import com.baeldung.jackson.dtos.User;
|
||||
import com.baeldung.jackson.dtos.withEnum.TypeEnumWithValue;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.jackson.annotation.BeanWithCreator;
|
||||
import com.baeldung.jackson.annotation.BeanWithCustomAnnotation;
|
||||
import com.baeldung.jackson.annotation.BeanWithFilter;
|
||||
@@ -30,16 +27,17 @@ import com.baeldung.jackson.annotation.RawBean;
|
||||
import com.baeldung.jackson.annotation.UnwrappedUser;
|
||||
import com.baeldung.jackson.annotation.UserWithIgnoreType;
|
||||
import com.baeldung.jackson.annotation.Zoo;
|
||||
import com.baeldung.jackson.bidirection.ItemWithIdentity;
|
||||
import com.baeldung.jackson.bidirection.ItemWithRef;
|
||||
import com.baeldung.jackson.bidirection.UserWithIdentity;
|
||||
import com.baeldung.jackson.bidirection.UserWithRef;
|
||||
import com.baeldung.jackson.date.EventWithFormat;
|
||||
import com.baeldung.jackson.date.EventWithSerializer;
|
||||
import com.baeldung.jackson.dtos.MyMixInForString;
|
||||
import com.baeldung.jackson.dtos.MyMixInForIgnoreType;
|
||||
import com.baeldung.jackson.dtos.withEnum.TypeEnumWithValue;
|
||||
import com.baeldung.jackson.exception.UserWithRoot;
|
||||
import com.baeldung.jackson.jsonview.Item;
|
||||
import com.baeldung.jackson.jsonview.Views;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.InjectableValues;
|
||||
@@ -127,7 +125,7 @@ public class JacksonAnnotationTest {
|
||||
public void whenDeserializingUsingJsonCreator_thenCorrect() throws JsonProcessingException, IOException {
|
||||
final String json = "{\"id\":1,\"theName\":\"My bean\"}";
|
||||
|
||||
final BeanWithCreator bean = new ObjectMapper().reader(BeanWithCreator.class).readValue(json);
|
||||
final BeanWithCreator bean = new ObjectMapper().readerFor(BeanWithCreator.class).readValue(json);
|
||||
assertEquals("My bean", bean.name);
|
||||
}
|
||||
|
||||
@@ -136,7 +134,7 @@ public class JacksonAnnotationTest {
|
||||
final String json = "{\"name\":\"My bean\"}";
|
||||
final InjectableValues inject = new InjectableValues.Std().addValue(int.class, 1);
|
||||
|
||||
final BeanWithInject bean = new ObjectMapper().reader(inject).withType(BeanWithInject.class).readValue(json);
|
||||
final BeanWithInject bean = new ObjectMapper().reader(inject).forType(BeanWithInject.class).readValue(json);
|
||||
assertEquals("My bean", bean.name);
|
||||
assertEquals(1, bean.id);
|
||||
}
|
||||
@@ -145,7 +143,7 @@ public class JacksonAnnotationTest {
|
||||
public void whenDeserializingUsingJsonAnySetter_thenCorrect() throws JsonProcessingException, IOException {
|
||||
final String json = "{\"name\":\"My bean\",\"attr2\":\"val2\",\"attr1\":\"val1\"}";
|
||||
|
||||
final ExtendableBean bean = new ObjectMapper().reader(ExtendableBean.class).readValue(json);
|
||||
final ExtendableBean bean = new ObjectMapper().readerFor(ExtendableBean.class).readValue(json);
|
||||
assertEquals("My bean", bean.name);
|
||||
assertEquals("val2", bean.getProperties().get("attr2"));
|
||||
}
|
||||
@@ -154,7 +152,7 @@ public class JacksonAnnotationTest {
|
||||
public void whenDeserializingUsingJsonSetter_thenCorrect() throws JsonProcessingException, IOException {
|
||||
final String json = "{\"id\":1,\"name\":\"My bean\"}";
|
||||
|
||||
final BeanWithGetter bean = new ObjectMapper().reader(BeanWithGetter.class).readValue(json);
|
||||
final BeanWithGetter bean = new ObjectMapper().readerFor(BeanWithGetter.class).readValue(json);
|
||||
assertEquals("My bean", bean.getTheName());
|
||||
}
|
||||
|
||||
@@ -164,7 +162,7 @@ public class JacksonAnnotationTest {
|
||||
|
||||
final SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
|
||||
|
||||
final EventWithSerializer event = new ObjectMapper().reader(EventWithSerializer.class).readValue(json);
|
||||
final EventWithSerializer event = new ObjectMapper().readerFor(EventWithSerializer.class).readValue(json);
|
||||
assertEquals("20-12-2014 02:30:00", df.format(event.eventDate));
|
||||
}
|
||||
|
||||
@@ -235,7 +233,7 @@ public class JacksonAnnotationTest {
|
||||
public void whenDeserializingPolymorphic_thenCorrect() throws JsonProcessingException, IOException {
|
||||
final String json = "{\"animal\":{\"name\":\"lacy\",\"type\":\"cat\"}}";
|
||||
|
||||
final Zoo zoo = new ObjectMapper().reader().withType(Zoo.class).readValue(json);
|
||||
final Zoo zoo = new ObjectMapper().readerFor(Zoo.class).readValue(json);
|
||||
|
||||
assertEquals("lacy", zoo.animal.name);
|
||||
assertEquals(Zoo.Cat.class, zoo.animal.getClass());
|
||||
@@ -250,7 +248,7 @@ public class JacksonAnnotationTest {
|
||||
assertThat(result, containsString("My bean"));
|
||||
assertThat(result, containsString("1"));
|
||||
|
||||
final BeanWithGetter resultBean = new ObjectMapper().reader(BeanWithGetter.class).readValue(result);
|
||||
final BeanWithGetter resultBean = new ObjectMapper().readerFor(BeanWithGetter.class).readValue(result);
|
||||
assertEquals("My bean", resultBean.getTheName());
|
||||
}
|
||||
|
||||
@@ -338,19 +336,19 @@ public class JacksonAnnotationTest {
|
||||
assertThat(result, not(containsString("dateCreated")));
|
||||
}
|
||||
|
||||
@Ignore("Jackson 2.7.1-1 seems to have changed the API regarding mixins")
|
||||
// @Ignore("Jackson 2.7.1-1 seems to have changed the API regarding mixins")
|
||||
@Test
|
||||
public void whenSerializingUsingMixInAnnotation_thenCorrect() throws JsonProcessingException {
|
||||
final User user = new User(1, "John");
|
||||
final com.baeldung.jackson.dtos.Item item = new com.baeldung.jackson.dtos.Item(1, "book", null);
|
||||
|
||||
String result = new ObjectMapper().writeValueAsString(user);
|
||||
assertThat(result, containsString("John"));
|
||||
String result = new ObjectMapper().writeValueAsString(item);
|
||||
assertThat(result, containsString("owner"));
|
||||
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.addMixIn(String.class, MyMixInForString.class);
|
||||
mapper.addMixIn(com.baeldung.jackson.dtos.User.class, MyMixInForIgnoreType.class);
|
||||
|
||||
result = mapper.writeValueAsString(user);
|
||||
assertThat(result, not(containsString("John")));
|
||||
result = mapper.writeValueAsString(item);
|
||||
assertThat(result, not(containsString("owner")));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -7,6 +7,8 @@ import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.jackson.bidirection.Item;
|
||||
import com.baeldung.jackson.bidirection.ItemWithIdentity;
|
||||
import com.baeldung.jackson.bidirection.ItemWithIgnore;
|
||||
@@ -20,8 +22,6 @@ import com.baeldung.jackson.bidirection.UserWithRef;
|
||||
import com.baeldung.jackson.bidirection.UserWithSerializer;
|
||||
import com.baeldung.jackson.bidirection.UserWithView;
|
||||
import com.baeldung.jackson.jsonview.Views;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@@ -93,7 +93,7 @@ public class JacksonBidirectionRelationTest {
|
||||
public void givenBidirectionRelation_whenDeserializingUsingIdentity_thenCorrect() throws JsonProcessingException, IOException {
|
||||
final String json = "{\"id\":2,\"itemName\":\"book\",\"owner\":{\"id\":1,\"name\":\"John\",\"userItems\":[2]}}";
|
||||
|
||||
final ItemWithIdentity item = new ObjectMapper().reader(ItemWithIdentity.class).readValue(json);
|
||||
final ItemWithIdentity item = new ObjectMapper().readerFor(ItemWithIdentity.class).readValue(json);
|
||||
|
||||
assertEquals(2, item.id);
|
||||
assertEquals("book", item.itemName);
|
||||
@@ -104,7 +104,7 @@ public class JacksonBidirectionRelationTest {
|
||||
public void givenBidirectionRelation_whenUsingCustomDeserializer_thenCorrect() throws JsonProcessingException, IOException {
|
||||
final String json = "{\"id\":2,\"itemName\":\"book\",\"owner\":{\"id\":1,\"name\":\"John\",\"userItems\":[2]}}";
|
||||
|
||||
final ItemWithSerializer item = new ObjectMapper().reader(ItemWithSerializer.class).readValue(json);
|
||||
final ItemWithSerializer item = new ObjectMapper().readerFor(ItemWithSerializer.class).readValue(json);
|
||||
assertEquals(2, item.id);
|
||||
assertEquals("book", item.itemName);
|
||||
assertEquals("John", item.owner.name);
|
||||
|
||||
@@ -11,15 +11,15 @@ import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import com.baeldung.jackson.date.EventWithLocalDateTime;
|
||||
import com.baeldung.jackson.date.Event;
|
||||
import com.baeldung.jackson.date.EventWithFormat;
|
||||
import com.baeldung.jackson.date.EventWithJodaTime;
|
||||
import com.baeldung.jackson.date.EventWithSerializer;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.jackson.date.Event;
|
||||
import com.baeldung.jackson.date.EventWithFormat;
|
||||
import com.baeldung.jackson.date.EventWithJodaTime;
|
||||
import com.baeldung.jackson.date.EventWithLocalDateTime;
|
||||
import com.baeldung.jackson.date.EventWithSerializer;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
@@ -128,7 +128,7 @@ public class JacksonDateTest {
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.setDateFormat(df);
|
||||
|
||||
final Event event = mapper.reader(Event.class).readValue(json);
|
||||
final Event event = mapper.readerFor(Event.class).readValue(json);
|
||||
assertEquals("20-12-2014 02:30:00", df.format(event.eventDate));
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ public class JacksonDateTest {
|
||||
final SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
final EventWithSerializer event = mapper.reader(EventWithSerializer.class).readValue(json);
|
||||
final EventWithSerializer event = mapper.readerFor(EventWithSerializer.class).readValue(json);
|
||||
assertEquals("20-12-2014 02:30:00", df.format(event.eventDate));
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,13 @@ import static org.junit.Assert.assertThat;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import com.baeldung.jackson.exception.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.jackson.exception.User;
|
||||
import com.baeldung.jackson.exception.UserWithPrivateFields;
|
||||
import com.baeldung.jackson.exception.UserWithRoot;
|
||||
import com.baeldung.jackson.exception.Zoo;
|
||||
import com.baeldung.jackson.exception.ZooConfigured;
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
@@ -30,7 +34,7 @@ public class JacksonExceptionsTest {
|
||||
final String json = "{\"animal\":{\"name\":\"lacy\"}}";
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
mapper.reader().withType(Zoo.class).readValue(json);
|
||||
mapper.reader().forType(Zoo.class).readValue(json);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -38,7 +42,7 @@ public class JacksonExceptionsTest {
|
||||
final String json = "{\"animal\":{\"name\":\"lacy\"}}";
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
mapper.reader().withType(ZooConfigured.class).readValue(json);
|
||||
mapper.reader().forType(ZooConfigured.class).readValue(json);
|
||||
}
|
||||
|
||||
// JsonMappingException: No serializer found for class
|
||||
@@ -67,7 +71,7 @@ public class JacksonExceptionsTest {
|
||||
final String json = "{\"id\":1,\"name\":\"John\"}";
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
mapper.reader().withType(User.class).readValue(json);
|
||||
mapper.reader().forType(User.class).readValue(json);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,7 +79,7 @@ public class JacksonExceptionsTest {
|
||||
final String json = "{\"id\":1,\"name\":\"John\"}";
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
final com.baeldung.jackson.dtos.User user = mapper.reader().withType(com.baeldung.jackson.dtos.User.class).readValue(json);
|
||||
final com.baeldung.jackson.dtos.User user = mapper.reader().forType(com.baeldung.jackson.dtos.User.class).readValue(json);
|
||||
assertEquals("John", user.name);
|
||||
}
|
||||
|
||||
@@ -87,7 +91,7 @@ public class JacksonExceptionsTest {
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE);
|
||||
|
||||
mapper.reader().withType(com.baeldung.jackson.dtos.User.class).readValue(json);
|
||||
mapper.reader().forType(com.baeldung.jackson.dtos.User.class).readValue(json);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -97,7 +101,7 @@ public class JacksonExceptionsTest {
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE);
|
||||
|
||||
final UserWithRoot user = mapper.reader().withType(UserWithRoot.class).readValue(json);
|
||||
final UserWithRoot user = mapper.reader().forType(UserWithRoot.class).readValue(json);
|
||||
assertEquals("John", user.name);
|
||||
}
|
||||
|
||||
@@ -107,7 +111,7 @@ public class JacksonExceptionsTest {
|
||||
final String json = "[{\"id\":1,\"name\":\"John\"},{\"id\":2,\"name\":\"Adam\"}]";
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
mapper.reader().withType(com.baeldung.jackson.dtos.User.class).readValue(json);
|
||||
mapper.reader().forType(com.baeldung.jackson.dtos.User.class).readValue(json);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -115,7 +119,7 @@ public class JacksonExceptionsTest {
|
||||
final String json = "[{\"id\":1,\"name\":\"John\"},{\"id\":2,\"name\":\"Adam\"}]";
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
final List<com.baeldung.jackson.dtos.User> users = mapper.reader().withType(new TypeReference<List<com.baeldung.jackson.dtos.User>>() {
|
||||
final List<com.baeldung.jackson.dtos.User> users = mapper.reader().forType(new TypeReference<List<com.baeldung.jackson.dtos.User>>() {
|
||||
}).readValue(json);
|
||||
|
||||
assertEquals(2, users.size());
|
||||
@@ -127,7 +131,7 @@ public class JacksonExceptionsTest {
|
||||
final String json = "{\"id\":1,\"name\":\"John\", \"checked\":true}";
|
||||
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.reader().withType(com.baeldung.jackson.dtos.User.class).readValue(json);
|
||||
mapper.reader().forType(com.baeldung.jackson.dtos.User.class).readValue(json);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -137,7 +141,7 @@ public class JacksonExceptionsTest {
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
|
||||
final com.baeldung.jackson.dtos.User user = mapper.reader().withType(com.baeldung.jackson.dtos.User.class).readValue(json);
|
||||
final com.baeldung.jackson.dtos.User user = mapper.reader().forType(com.baeldung.jackson.dtos.User.class).readValue(json);
|
||||
assertEquals("John", user.name);
|
||||
}
|
||||
|
||||
@@ -147,7 +151,7 @@ public class JacksonExceptionsTest {
|
||||
final String json = "{'id':1,'name':'John'}";
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
mapper.reader().withType(com.baeldung.jackson.dtos.User.class).readValue(json);
|
||||
mapper.reader().forType(com.baeldung.jackson.dtos.User.class).readValue(json);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -158,7 +162,7 @@ public class JacksonExceptionsTest {
|
||||
factory.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES);
|
||||
final ObjectMapper mapper = new ObjectMapper(factory);
|
||||
|
||||
final com.baeldung.jackson.dtos.User user = mapper.reader().withType(com.baeldung.jackson.dtos.User.class).readValue(json);
|
||||
final com.baeldung.jackson.dtos.User user = mapper.reader().forType(com.baeldung.jackson.dtos.User.class).readValue(json);
|
||||
assertEquals("John", user.name);
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user