Home
Name Modified Size InfoDownloads / Week
readme.txt 2019-01-14 3.8 kB
Totals: 1 Item   3.8 kB 0
<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>org.sooo</groupId>
  <artifactId>gson-example</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>gson-example</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
  	<dependency>
  		<groupId>junit</groupId>
  		<artifactId>junit</artifactId>
  		<version>4.10</version>
  		<scope>test</scope>
  	</dependency>
  	<dependency>
  		<groupId>com.google.code.gson</groupId>
  		<artifactId>gson</artifactId>
  		<version>2.1</version>
  	</dependency>
  	<dependency>
  		<groupId>com.google.guava</groupId>
  		<artifactId>guava</artifactId>
  		<version>11.0.2</version>
  	</dependency>
  	<dependency>
  		<groupId>org.slf4j</groupId>
  		<artifactId>slf4j-simple</artifactId>
  		<version>1.6.4</version>
  	</dependency>
  	<dependency>
  		<groupId>com.googlecode.json-simple</groupId>
  		<artifactId>json-simple</artifactId>
  		<version>1.1</version>
  	</dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.5.4</version>
        </dependency>
        <dependency>
            <groupId>org.jsonschema2pojo</groupId>
            <artifactId>jsonschema2pojo-core</artifactId>
            <version>1.0.0</version>
        </dependency>
  </dependencies>



  <build>
	<plugins>
		<plugin>
		    <groupId>org.apache.maven.plugins</groupId>
		    <artifactId>maven-compiler-plugin</artifactId>
		     <version>3.8.0</version>
		     <configuration>
		        <source>1.8</source>
		        <target>1.8</target>
		    </configuration>
		</plugin>
		<plugin>
			<groupId>org.jsonschema2pojo</groupId>
			<artifactId>jsonschema2pojo-maven-plugin</artifactId>
			<version>1.0.0</version>
			<configuration>
				<sourceDirectory>${basedir}/src/main/resources/json/web.json</sourceDirectory>
				<targetPackage>gen.model</targetPackage>				
				<sourceType>json</sourceType>
				<generateBuilders>false</generateBuilders>
				<includeGetters>true</includeGetters>
				<includeConstructors>false</includeConstructors>
				<targetLanguage>java</targetLanguage>
				<annotationStyle>gson</annotationStyle>
				<addCompileSourceRoot>true</addCompileSourceRoot>
				<constructorsRequiredPropertiesOnly>true</constructorsRequiredPropertiesOnly>		
			</configuration>
			<executions>
				<execution>
					<goals>
						<goal>generate</goal>
					</goals>
				</execution>
			</executions>
		</plugin>
	</plugins>
  </build>

</project>

package org.sooo;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import java.io.FileNotFoundException;
import java.io.FileReader;


import org.junit.Test;

import com.google.gson.Gson;
import com.google.gson.stream.JsonReader;

//import org.junit.Test;
import gen.model.Web;

public class GsonFromFileTest {

	private Gson gson = new Gson();
	
	@Test
	public void json2Class() throws FileNotFoundException {
		JsonReader jsonReader = new JsonReader(new FileReader("/home/linus/workspace_neon/gson-example/src/main
/resources/json/web.json"));
		Web data = gson.fromJson(jsonReader, Web.class);
		// then
		assertThat(data.getWebApp().getServlet().get(0).getServletName(),is("cofaxCDS"));

	}


}







Source: readme.txt, updated 2019-01-14