Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
8881fdcaf4
1
apache-cxf/cxf-spring/.gitignore
vendored
Normal file
1
apache-cxf/cxf-spring/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
target/
|
@ -8,18 +8,42 @@
|
|||||||
<artifactId>apache-cxf</artifactId>
|
<artifactId>apache-cxf</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<properties>
|
|
||||||
<cxf.version>3.1.6</cxf.version>
|
<dependencies>
|
||||||
<spring.version>4.3.1.RELEASE</spring.version>
|
<dependency>
|
||||||
<surefire.version>2.19.1</surefire.version>
|
<groupId>org.apache.cxf</groupId>
|
||||||
</properties>
|
<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>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-context</artifactId>
|
||||||
|
<version>${spring.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-webmvc</artifactId>
|
||||||
|
<version>${spring.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-war-plugin</artifactId>
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
<version>2.6</version>
|
<version>2.6</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
|
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
@ -33,6 +57,7 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<profiles>
|
<profiles>
|
||||||
<profile>
|
<profile>
|
||||||
<id>integration</id>
|
<id>integration</id>
|
||||||
@ -41,16 +66,16 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.cargo</groupId>
|
<groupId>org.codehaus.cargo</groupId>
|
||||||
<artifactId>cargo-maven2-plugin</artifactId>
|
<artifactId>cargo-maven2-plugin</artifactId>
|
||||||
<version>1.5.0</version>
|
<version>1.4.19</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<container>
|
<container>
|
||||||
<containerId>jetty9x</containerId>
|
<containerId>tomcat8x</containerId>
|
||||||
<type>embedded</type>
|
<type>embedded</type>
|
||||||
</container>
|
</container>
|
||||||
<configuration>
|
<configuration>
|
||||||
<properties>
|
<properties>
|
||||||
<cargo.hostname>localhost</cargo.hostname>
|
<cargo.hostname>localhost</cargo.hostname>
|
||||||
<cargo.servlet.port>8080</cargo.servlet.port>
|
<cargo.servlet.port>8081</cargo.servlet.port>
|
||||||
</properties>
|
</properties>
|
||||||
</configuration>
|
</configuration>
|
||||||
</configuration>
|
</configuration>
|
||||||
@ -71,6 +96,7 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>${surefire.version}</version>
|
<version>${surefire.version}</version>
|
||||||
@ -91,27 +117,13 @@
|
|||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</profile>
|
</profile>
|
||||||
|
|
||||||
</profiles>
|
</profiles>
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
<properties>
|
||||||
<groupId>org.apache.cxf</groupId>
|
<cxf.version>3.1.6</cxf.version>
|
||||||
<artifactId>cxf-rt-frontend-jaxws</artifactId>
|
<spring.version>4.3.1.RELEASE</spring.version>
|
||||||
<version>${cxf.version}</version>
|
<surefire.version>2.19.1</surefire.version>
|
||||||
</dependency>
|
</properties>
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.cxf</groupId>
|
|
||||||
<artifactId>cxf-rt-transports-http-jetty</artifactId>
|
|
||||||
<version>${cxf.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-context</artifactId>
|
|
||||||
<version>${spring.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-web</artifactId>
|
|
||||||
<version>${spring.version}</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.baeldung.cxf.spring;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
import javax.servlet.ServletRegistration;
|
||||||
|
|
||||||
|
import org.apache.cxf.transport.servlet.CXFServlet;
|
||||||
|
import org.springframework.web.WebApplicationInitializer;
|
||||||
|
import org.springframework.web.context.ContextLoaderListener;
|
||||||
|
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||||
|
|
||||||
|
public class AppInitializer implements WebApplicationInitializer {
|
||||||
|
@Override
|
||||||
|
public void onStartup(ServletContext container) {
|
||||||
|
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|
||||||
|
context.register(ServiceConfiguration.class);
|
||||||
|
container.addListener(new ContextLoaderListener(context));
|
||||||
|
|
||||||
|
ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new CXFServlet());
|
||||||
|
dispatcher.addMapping("/services/*");
|
||||||
|
}
|
||||||
|
}
|
@ -5,5 +5,6 @@ import javax.jws.WebService;
|
|||||||
@WebService
|
@WebService
|
||||||
public interface Baeldung {
|
public interface Baeldung {
|
||||||
String hello(String name);
|
String hello(String name);
|
||||||
|
|
||||||
String register(Student student);
|
String register(Student student);
|
||||||
}
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.baeldung.cxf.spring;
|
||||||
|
|
||||||
|
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class ClientConfiguration {
|
||||||
|
@Bean(name = "client")
|
||||||
|
public Object generateProxy() {
|
||||||
|
return proxyFactoryBean().create();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public JaxWsProxyFactoryBean proxyFactoryBean() {
|
||||||
|
JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
|
||||||
|
proxyFactory.setServiceClass(Baeldung.class);
|
||||||
|
proxyFactory.setAddress("http://localhost:8081/services/baeldung");
|
||||||
|
return proxyFactory;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.baeldung.cxf.spring;
|
||||||
|
|
||||||
|
import javax.xml.ws.Endpoint;
|
||||||
|
|
||||||
|
import org.apache.cxf.Bus;
|
||||||
|
import org.apache.cxf.bus.spring.SpringBus;
|
||||||
|
import org.apache.cxf.jaxws.EndpointImpl;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class ServiceConfiguration {
|
||||||
|
@Bean(name = Bus.DEFAULT_BUS_ID)
|
||||||
|
public SpringBus springBus() {
|
||||||
|
return new SpringBus();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Endpoint endpoint() {
|
||||||
|
EndpointImpl endpoint = new EndpointImpl(springBus(), new BaeldungImpl());
|
||||||
|
endpoint.publish("http://localhost:8081/services/baeldung");
|
||||||
|
return endpoint;
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
|
|
||||||
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schema/jaxws.xsd">
|
|
||||||
<bean id="client" factory-bean="clientFactory" factory-method="create" />
|
|
||||||
<bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
|
|
||||||
<property name="serviceClass" value="com.baeldung.cxf.spring.Baeldung" />
|
|
||||||
<property name="address" value="http://localhost:8080/services/baeldung" />
|
|
||||||
</bean>
|
|
||||||
</beans>
|
|
@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
|
|
||||||
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
|
|
||||||
<jaxws:endpoint id="baeldung"
|
|
||||||
implementor="com.baeldung.cxf.spring.BaeldungImpl" address="http://localhost:8080/services/baeldung" />
|
|
||||||
</beans>
|
|
@ -1,14 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
version="3.0"
|
|
||||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
|
|
||||||
<servlet>
|
|
||||||
<servlet-name>cxf</servlet-name>
|
|
||||||
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
|
|
||||||
<load-on-startup>1</load-on-startup>
|
|
||||||
</servlet>
|
|
||||||
<servlet-mapping>
|
|
||||||
<servlet-name>cxf</servlet-name>
|
|
||||||
<url-pattern>/services/*</url-pattern>
|
|
||||||
</servlet-mapping>
|
|
||||||
</web-app>
|
|
@ -3,15 +3,12 @@ package com.baeldung.cxf.spring;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
|
|
||||||
public class StudentTest {
|
public class StudentTest {
|
||||||
private ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "client-beans.xml" });
|
private ApplicationContext context = new AnnotationConfigApplicationContext(ClientConfiguration.class);
|
||||||
private Baeldung baeldungProxy;
|
private Baeldung baeldungProxy = (Baeldung) context.getBean("client");
|
||||||
|
|
||||||
{
|
|
||||||
baeldungProxy = (Baeldung) context.getBean("client");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenUsingHelloMethod_thenCorrect() {
|
public void whenUsingHelloMethod_thenCorrect() {
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
@ -9,7 +8,7 @@
|
|||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
|
|
||||||
<name>Resource vs Inject vs Autowired</name>
|
<name>dependency-injection</name>
|
||||||
<description>Accompanying the demonstration of the use of the annotations related to injection mechanisms, namely
|
<description>Accompanying the demonstration of the use of the annotations related to injection mechanisms, namely
|
||||||
Resource, Inject, and Autowired
|
Resource, Inject, and Autowired
|
||||||
</description>
|
</description>
|
||||||
@ -54,6 +53,7 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
@ -71,13 +71,29 @@
|
|||||||
</includes>
|
</includes>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
|
<version>${maven-war-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven-war-plugin.version>2.6</maven-war-plugin.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>java.net</id>
|
<id>java.net</id>
|
||||||
<url>https://maven.java.net/content/repositories/releases/</url>
|
<url>https://maven.java.net/content/repositories/releases/</url>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -7,9 +7,19 @@ import java.util.List;
|
|||||||
import com.fasterxml.jackson.core.JsonParser;
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||||||
|
|
||||||
public class CustomListDeserializer extends JsonDeserializer<List<ItemWithSerializer>> {
|
public class CustomListDeserializer extends StdDeserializer<List<ItemWithSerializer>> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1095767961632979804L;
|
||||||
|
|
||||||
|
public CustomListDeserializer() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomListDeserializer(final Class<?> vc) {
|
||||||
|
super(vc);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ItemWithSerializer> deserialize(final JsonParser jsonparser, final DeserializationContext context) throws IOException, JsonProcessingException {
|
public List<ItemWithSerializer> deserialize(final JsonParser jsonparser, final DeserializationContext context) throws IOException, JsonProcessingException {
|
||||||
|
@ -6,11 +6,20 @@ import java.util.List;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
|
||||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||||
|
|
||||||
public class CustomListSerializer extends JsonSerializer<List<ItemWithSerializer>> {
|
public class CustomListSerializer extends StdSerializer<List<ItemWithSerializer>> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 3698763098000900856L;
|
||||||
|
|
||||||
|
public CustomListSerializer() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomListSerializer(final Class<List<ItemWithSerializer>> t) {
|
||||||
|
super(t);
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public void serialize(final List<ItemWithSerializer> items, final JsonGenerator generator, final SerializerProvider provider) throws IOException, JsonProcessingException {
|
public void serialize(final List<ItemWithSerializer> items, final JsonGenerator generator, final SerializerProvider provider) throws IOException, JsonProcessingException {
|
||||||
final List<Integer> ids = new ArrayList<Integer>();
|
final List<Integer> ids = new ArrayList<Integer>();
|
||||||
|
@ -8,12 +8,21 @@ import java.util.Date;
|
|||||||
import com.fasterxml.jackson.core.JsonParser;
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||||||
|
|
||||||
public class CustomDateDeserializer extends JsonDeserializer<Date> {
|
public class CustomDateDeserializer extends StdDeserializer<Date> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -5451717385630622729L;
|
||||||
private SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
|
private SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
|
||||||
|
|
||||||
|
public CustomDateDeserializer() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomDateDeserializer(final Class<?> vc) {
|
||||||
|
super(vc);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Date deserialize(final JsonParser jsonparser, final DeserializationContext context) throws IOException, JsonProcessingException {
|
public Date deserialize(final JsonParser jsonparser, final DeserializationContext context) throws IOException, JsonProcessingException {
|
||||||
final String date = jsonparser.getText();
|
final String date = jsonparser.getText();
|
||||||
|
@ -6,13 +6,22 @@ import java.util.Date;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
|
||||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||||
|
|
||||||
public class CustomDateSerializer extends JsonSerializer<Date> {
|
public class CustomDateSerializer extends StdSerializer<Date> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -2894356342227378312L;
|
||||||
private SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
|
private SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
|
||||||
|
|
||||||
|
public CustomDateSerializer() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomDateSerializer(final Class<Date> t) {
|
||||||
|
super(t);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(final Date value, final JsonGenerator gen, final SerializerProvider arg2) throws IOException, JsonProcessingException {
|
public void serialize(final Date value, final JsonGenerator gen, final SerializerProvider arg2) throws IOException, JsonProcessingException {
|
||||||
gen.writeString(formatter.format(value));
|
gen.writeString(formatter.format(value));
|
||||||
|
@ -8,10 +8,20 @@ import org.joda.time.format.DateTimeFormatter;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
|
||||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||||
|
|
||||||
public class CustomDateTimeSerializer extends JsonSerializer<DateTime> {
|
public class CustomDateTimeSerializer extends StdSerializer<DateTime> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -3927232057990121460L;
|
||||||
|
|
||||||
|
public CustomDateTimeSerializer() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomDateTimeSerializer(final Class<DateTime> t) {
|
||||||
|
super(t);
|
||||||
|
}
|
||||||
|
|
||||||
private static DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm");
|
private static DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm");
|
||||||
|
|
||||||
|
@ -6,13 +6,23 @@ import java.time.format.DateTimeFormatter;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
|
||||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||||
|
|
||||||
public class CustomLocalDateTimeSerializer extends JsonSerializer<LocalDateTime> {
|
public class CustomLocalDateTimeSerializer extends StdSerializer<LocalDateTime> {
|
||||||
|
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -7449444168934819290L;
|
||||||
private static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
|
private static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
|
||||||
|
|
||||||
|
public CustomLocalDateTimeSerializer() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomLocalDateTimeSerializer(final Class<LocalDateTime> t) {
|
||||||
|
super(t);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(final LocalDateTime value, final JsonGenerator gen, final SerializerProvider arg2) throws IOException, JsonProcessingException {
|
public void serialize(final LocalDateTime value, final JsonGenerator gen, final SerializerProvider arg2) throws IOException, JsonProcessingException {
|
||||||
gen.writeString(formatter.format(value));
|
gen.writeString(formatter.format(value));
|
||||||
|
@ -2,17 +2,26 @@ package com.baeldung.jackson.deserialization;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.baeldung.jackson.dtos.User;
|
|
||||||
import com.baeldung.jackson.dtos.Item;
|
import com.baeldung.jackson.dtos.Item;
|
||||||
|
import com.baeldung.jackson.dtos.User;
|
||||||
import com.fasterxml.jackson.core.JsonParser;
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||||||
import com.fasterxml.jackson.databind.node.IntNode;
|
import com.fasterxml.jackson.databind.node.IntNode;
|
||||||
|
|
||||||
public class ItemDeserializer extends JsonDeserializer<Item> {
|
public class ItemDeserializer extends StdDeserializer<Item> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1883547683050039861L;
|
||||||
|
|
||||||
|
public ItemDeserializer() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemDeserializer(final Class<?> vc) {
|
||||||
|
super(vc);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {"id":1,"itemNr":"theItem","owner":2}
|
* {"id":1,"itemNr":"theItem","owner":2}
|
||||||
|
@ -4,15 +4,24 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import com.baeldung.jackson.dtos.ItemWithSerializer;
|
import com.baeldung.jackson.dtos.ItemWithSerializer;
|
||||||
import com.baeldung.jackson.dtos.User;
|
import com.baeldung.jackson.dtos.User;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonParser;
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||||||
import com.fasterxml.jackson.databind.node.IntNode;
|
import com.fasterxml.jackson.databind.node.IntNode;
|
||||||
|
|
||||||
public class ItemDeserializerOnClass extends JsonDeserializer<ItemWithSerializer> {
|
public class ItemDeserializerOnClass extends StdDeserializer<ItemWithSerializer> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 5579141241817332594L;
|
||||||
|
|
||||||
|
public ItemDeserializerOnClass() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemDeserializerOnClass(final Class<?> vc) {
|
||||||
|
super(vc);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {"id":1,"itemNr":"theItem","owner":2}
|
* {"id":1,"itemNr":"theItem","owner":2}
|
||||||
|
@ -4,10 +4,20 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
|
||||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||||
|
|
||||||
public class TypeSerializer extends JsonSerializer<TypeEnumWithCustomSerializer> {
|
public class TypeSerializer extends StdSerializer<TypeEnumWithCustomSerializer> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -7650668914169390772L;
|
||||||
|
|
||||||
|
public TypeSerializer() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TypeSerializer(final Class<TypeEnumWithCustomSerializer> t) {
|
||||||
|
super(t);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(final TypeEnumWithCustomSerializer value, final JsonGenerator generator, final SerializerProvider provider) throws IOException, JsonProcessingException {
|
public void serialize(final TypeEnumWithCustomSerializer value, final JsonGenerator generator, final SerializerProvider provider) throws IOException, JsonProcessingException {
|
||||||
|
@ -3,13 +3,22 @@ package com.baeldung.jackson.serialization;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.baeldung.jackson.dtos.Item;
|
import com.baeldung.jackson.dtos.Item;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
|
||||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||||
|
|
||||||
public class ItemSerializer extends JsonSerializer<Item> {
|
public class ItemSerializer extends StdSerializer<Item> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 6739170890621978901L;
|
||||||
|
|
||||||
|
public ItemSerializer() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemSerializer(final Class<Item> t) {
|
||||||
|
super(t);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void serialize(final Item value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException {
|
public final void serialize(final Item value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException {
|
||||||
|
@ -3,13 +3,22 @@ package com.baeldung.jackson.serialization;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.baeldung.jackson.dtos.ItemWithSerializer;
|
import com.baeldung.jackson.dtos.ItemWithSerializer;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
|
||||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||||
|
|
||||||
public class ItemSerializerOnClass extends JsonSerializer<ItemWithSerializer> {
|
public class ItemSerializerOnClass extends StdSerializer<ItemWithSerializer> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -1760959597313610409L;
|
||||||
|
|
||||||
|
public ItemSerializerOnClass() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemSerializerOnClass(final Class<ItemWithSerializer> t) {
|
||||||
|
super(t);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void serialize(final ItemWithSerializer value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException {
|
public final void serialize(final ItemWithSerializer value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException {
|
||||||
|
@ -4,10 +4,20 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
|
||||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||||
|
|
||||||
public class MyDtoNullKeySerializer extends JsonSerializer<Object> {
|
public class MyDtoNullKeySerializer extends StdSerializer<Object> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -4478531309177369056L;
|
||||||
|
|
||||||
|
public MyDtoNullKeySerializer() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MyDtoNullKeySerializer(final Class<Object> t) {
|
||||||
|
super(t);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(final Object value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException {
|
public void serialize(final Object value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException {
|
||||||
|
@ -6,10 +6,19 @@ import com.fasterxml.jackson.core.JsonParser;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.core.ObjectCodec;
|
import com.fasterxml.jackson.core.ObjectCodec;
|
||||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||||||
|
|
||||||
public class RestLoaderRequestDeserializer extends JsonDeserializer<RestLoaderRequest<IEntity>> {
|
public class RestLoaderRequestDeserializer extends StdDeserializer<RestLoaderRequest<IEntity>> {
|
||||||
|
private static final long serialVersionUID = -4245207329377196889L;
|
||||||
|
|
||||||
|
public RestLoaderRequestDeserializer() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RestLoaderRequestDeserializer(final Class<?> vc) {
|
||||||
|
super(vc);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RestLoaderRequest<IEntity> deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
public RestLoaderRequest<IEntity> deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
||||||
|
7
json/README.md
Normal file
7
json/README.md
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
=========
|
||||||
|
|
||||||
|
## Fast-Json
|
||||||
|
|
||||||
|
### Relevant Articles:
|
||||||
|
- [Introduction to JSON Schema in Java](http://www.baeldung.com/introduction-to-json-schema-in-java)
|
||||||
|
- [A Guide to FastJson](http://www.baeldung.com/????????)
|
@ -13,6 +13,12 @@
|
|||||||
<version>1.3.0</version>
|
<version>1.3.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>fastjson</artifactId>
|
||||||
|
<version>1.2.13</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.baeldung.json.schema;
|
package com.baeldung.json.schema;
|
||||||
|
|
||||||
import org.everit.json.schema.Schema;
|
import org.everit.json.schema.Schema;
|
||||||
|
import org.everit.json.schema.ValidationException;
|
||||||
import org.everit.json.schema.loader.SchemaLoader;
|
import org.everit.json.schema.loader.SchemaLoader;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@ -9,7 +10,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
public class JSONSchemaTest {
|
public class JSONSchemaTest {
|
||||||
|
|
||||||
@Test
|
@Test(expected = ValidationException.class)
|
||||||
public void givenInvalidInput_whenValidating_thenInvalid() {
|
public void givenInvalidInput_whenValidating_thenInvalid() {
|
||||||
|
|
||||||
JSONObject jsonSchema = new JSONObject(new JSONTokener(JSONSchemaTest.class.getResourceAsStream("/schema.json")));
|
JSONObject jsonSchema = new JSONObject(new JSONTokener(JSONSchemaTest.class.getResourceAsStream("/schema.json")));
|
104
json/src/test/java/fast_json/FastJsonTests.java
Normal file
104
json/src/test/java/fast_json/FastJsonTests.java
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
package fast_json;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.serializer.BeanContext;
|
||||||
|
import com.alibaba.fastjson.serializer.ContextValueFilter;
|
||||||
|
import com.alibaba.fastjson.serializer.NameFilter;
|
||||||
|
import com.alibaba.fastjson.serializer.SerializeConfig;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
public class FastJsonTests {
|
||||||
|
private List<Person> listOfPersons;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
listOfPersons = new ArrayList<Person>();
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.set(2016, 6, 24);
|
||||||
|
listOfPersons.add(new Person(15, "John", "Doe", calendar.getTime()));
|
||||||
|
listOfPersons.add(new Person(20, "Janette", "Doe", calendar.getTime()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenJavaList_thanConvertToJsonCorrect() {
|
||||||
|
String personJsonFormat = JSON.toJSONString(listOfPersons);
|
||||||
|
assertEquals(
|
||||||
|
personJsonFormat,
|
||||||
|
"[{\"FIRST NAME\":\"Doe\",\"LAST NAME\":\"John\",\"DATE OF BIRTH\":"
|
||||||
|
+ "\"24/07/2016\"},{\"FIRST NAME\":\"Doe\",\"LAST NAME\":\"Janette\",\"DATE OF BIRTH\":"
|
||||||
|
+ "\"24/07/2016\"}]");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenJson_thanConvertToObjectCorrect() {
|
||||||
|
String personJsonFormat = JSON.toJSONString(listOfPersons.get(0));
|
||||||
|
Person newPerson = JSON.parseObject(personJsonFormat, Person.class);
|
||||||
|
assertEquals(newPerson.getAge(), 0); // serialize is set to false for age attribute
|
||||||
|
assertEquals(newPerson.getFirstName(), listOfPersons.get(0).getFirstName());
|
||||||
|
assertEquals(newPerson.getLastName(), listOfPersons.get(0).getLastName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenGenerateJson_thanGenerationCorrect() throws ParseException {
|
||||||
|
JSONArray jsonArray = new JSONArray();
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("FIRST NAME", "John" + i);
|
||||||
|
jsonObject.put("LAST NAME", "Doe" + i);
|
||||||
|
jsonObject.put("DATE OF BIRTH", "2016/12/12 12:12:12");
|
||||||
|
jsonArray.add(jsonObject);
|
||||||
|
}
|
||||||
|
assertEquals(
|
||||||
|
jsonArray.toString(),
|
||||||
|
"[{\"LAST NAME\":\"Doe0\",\"DATE OF BIRTH\":"
|
||||||
|
+ "\"2016/12/12 12:12:12\",\"FIRST NAME\":\"John0\"},{\"LAST NAME\":\"Doe1\","
|
||||||
|
+ "\"DATE OF BIRTH\":\"2016/12/12 12:12:12\",\"FIRST NAME\":\"John1\"}]");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenContextFilter_whenJavaObject_thanJsonCorrect() {
|
||||||
|
ContextValueFilter valueFilter = new ContextValueFilter() {
|
||||||
|
public Object process(BeanContext context, Object object,
|
||||||
|
String name, Object value) {
|
||||||
|
if (name.equals("DATE OF BIRTH")) {
|
||||||
|
return "NOT TO DISCLOSE";
|
||||||
|
}
|
||||||
|
if (value.equals("John") || value.equals("Doe")) {
|
||||||
|
return ((String) value).toUpperCase();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
JSON.toJSONString(listOfPersons, valueFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenSerializeConfig_whenJavaObject_thanJsonCorrect() {
|
||||||
|
NameFilter formatName = new NameFilter() {
|
||||||
|
public String process(Object object, String name, Object value) {
|
||||||
|
return name.toLowerCase().replace(" ", "_");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
SerializeConfig.getGlobalInstance().addFilter(Person.class, formatName);
|
||||||
|
String jsonOutput = JSON.toJSONStringWithDateFormat(listOfPersons,
|
||||||
|
"yyyy-MM-dd");
|
||||||
|
assertEquals(
|
||||||
|
jsonOutput,
|
||||||
|
"[{\"first_name\":\"Doe\",\"last_name\":\"John\","
|
||||||
|
+ "\"date_of_birth\":\"2016-07-24\"},{\"first_name\":\"Doe\",\"last_name\":"
|
||||||
|
+ "\"Janette\",\"date_of_birth\":\"2016-07-24\"}]");
|
||||||
|
// resetting custom serializer
|
||||||
|
SerializeConfig.getGlobalInstance().put(Person.class, null);
|
||||||
|
}
|
||||||
|
}
|
70
json/src/test/java/fast_json/Person.java
Normal file
70
json/src/test/java/fast_json/Person.java
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
package fast_json;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class Person {
|
||||||
|
|
||||||
|
@JSONField(name = "AGE", serialize = false, deserialize = false)
|
||||||
|
private int age;
|
||||||
|
|
||||||
|
@JSONField(name = "LAST NAME", ordinal = 2)
|
||||||
|
private String lastName;
|
||||||
|
|
||||||
|
@JSONField(name = "FIRST NAME", ordinal = 1)
|
||||||
|
private String firstName;
|
||||||
|
|
||||||
|
@JSONField(name = "DATE OF BIRTH", format = "dd/MM/yyyy", ordinal = 3)
|
||||||
|
private Date dateOfBirth;
|
||||||
|
|
||||||
|
public Person() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Person(int age, String lastName, String firstName, Date dateOfBirth) {
|
||||||
|
super();
|
||||||
|
this.age = age;
|
||||||
|
this.lastName = lastName;
|
||||||
|
this.firstName = firstName;
|
||||||
|
this.dateOfBirth = dateOfBirth;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Person [age=" + age + ", lastName=" + lastName + ", firstName="
|
||||||
|
+ firstName + ", dateOfBirth=" + dateOfBirth + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAge() {
|
||||||
|
return age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAge(int age) {
|
||||||
|
this.age = age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastName() {
|
||||||
|
return lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastName(String lastName) {
|
||||||
|
this.lastName = lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFirstName() {
|
||||||
|
return firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFirstName(String firstName) {
|
||||||
|
this.firstName = firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDateOfBirth() {
|
||||||
|
return dateOfBirth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDateOfBirth(Date dateOfBirth) {
|
||||||
|
this.dateOfBirth = dateOfBirth;
|
||||||
|
}
|
||||||
|
}
|
2
pom.xml
2
pom.xml
@ -45,7 +45,7 @@
|
|||||||
<!-- <module>jpa-storedprocedure</module> -->
|
<!-- <module>jpa-storedprocedure</module> -->
|
||||||
<module>querydsl</module>
|
<module>querydsl</module>
|
||||||
<!-- <module>raml</module> -->
|
<!-- <module>raml</module> -->
|
||||||
<module>rest-assured-tutorial</module>
|
<module>rest-assured</module>
|
||||||
<module>rest-testing</module>
|
<module>rest-testing</module>
|
||||||
<module>resteasy</module>
|
<module>resteasy</module>
|
||||||
<module>log4j</module>
|
<module>log4j</module>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>rest-assured-tutorial</artifactId>
|
<artifactId>rest-assured</artifactId>
|
||||||
<version>1.0</version>
|
<version>1.0</version>
|
||||||
<name>rest-assured</name>
|
<name>rest-assured</name>
|
||||||
<build>
|
<build>
|
@ -3,4 +3,5 @@
|
|||||||
<installed facet="wst.jsdt.web" version="1.0"/>
|
<installed facet="wst.jsdt.web" version="1.0"/>
|
||||||
<installed facet="jst.web" version="3.0"/>
|
<installed facet="jst.web" version="3.0"/>
|
||||||
<installed facet="java" version="1.8"/>
|
<installed facet="java" version="1.8"/>
|
||||||
|
<installed facet="jpt.jpa" version="2.1"/>
|
||||||
</faceted-project>
|
</faceted-project>
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package com.baeldung.mvc.velocity.service;
|
package com.baeldung.mvc.velocity.service;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.baeldung.mvc.velocity.domain.Tutorial;
|
import com.baeldung.mvc.velocity.domain.Tutorial;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface ITutorialsService {
|
public interface ITutorialsService {
|
||||||
|
|
||||||
public List<Tutorial> listTutorials();
|
List<Tutorial> listTutorials();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user