new jackson sandboxed work

This commit is contained in:
eugenp 2013-12-30 17:17:49 +02:00
parent a4a6fcf569
commit bde8a4b73b
5 changed files with 93 additions and 3 deletions

View File

@ -13,7 +13,12 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>15.0</version>
<version>16.0-rc1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
@ -102,10 +107,10 @@
<!-- persistence -->
<hibernate.version>4.3.0.Final</hibernate.version>
<mysql-connector-java.version>5.1.27</mysql-connector-java.version>
<!-- marshalling -->
<jackson.version>2.3.0</jackson.version>
<!-- logging -->
<org.slf4j.version>1.7.5</org.slf4j.version>
<logback.version>1.0.11</logback.version>

View File

@ -0,0 +1,12 @@
{
"collection": [
{
"name": "Test order1",
"detail": "ahk ks"
},
{
"name": "Test order2",
"detail": "Fisteku"
}
]
}

View File

@ -0,0 +1,10 @@
[
{
"name": "Test order1",
"detail": "ahk ks"
},
{
"name": "Test order2",
"detail": "Fisteku"
}
]

View File

@ -0,0 +1,32 @@
package org.baeldung.jackson.try1;
public class COrder {
private String name;
private String detail;
//
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public String getDetail() {
return detail;
}
public void setDetail(final String detail) {
this.detail = detail;
}
//
@Override
public String toString() {
return "COrder [name=" + name + ", detail=" + detail + ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + ", toString()=" + super.toString() + "]";
}
}

View File

@ -0,0 +1,31 @@
package org.baeldung.jackson.try1;
import static org.junit.Assert.assertNotNull;
import java.io.IOException;
import java.net.URL;
import java.util.Collection;
import org.junit.Test;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Charsets;
import com.google.common.io.Resources;
public class JacksonTryUnitTest {
@Test
public final void whenDeserializing_thenCorrect() throws JsonParseException, JsonMappingException, IOException {
final URL url = Resources.getResource("example2.json");
final String jsonAsString = Resources.toString(url, Charsets.UTF_8);
final Collection<COrder> readValues = new ObjectMapper().readValue(jsonAsString, new TypeReference<Collection<COrder>>() {
});
assertNotNull(readValues);
}
}