Created
August 30, 2017 08:16
-
-
Save dmikurube/7ff6d073fbbf0e5f93e2d24e213514e2 to your computer and use it in GitHub Desktop.
JacksonExp.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'java' | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
compile 'com.fasterxml.jackson.core:jackson-core:2.6.7' | |
compile 'com.fasterxml.jackson.core:jackson-databind:2.6.7' | |
testCompile 'junit:junit:4.+' | |
} | |
sourceSets { | |
main { | |
java { | |
srcDir '.' | |
exclude 'Test*.java' | |
} | |
} | |
test { | |
java { | |
srcDir '.' | |
include 'Test*.java' | |
} | |
} | |
} | |
test { | |
testLogging { | |
events 'passed', 'skipped', 'failed', 'standardOut', 'standardError' | |
} | |
} | |
task run(type:JavaExec) { | |
main = project.hasProperty('main') ? project.getProperty('main') : 'JacksonExp' | |
classpath = sourceSets.main.runtimeClasspath | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.fasterxml.jackson.databind.ObjectMapper; | |
public class JacksonExp { | |
public static void main(String[] args) throws java.io.IOException { | |
final String json = "{\"id\":12345e3}"; | |
final ObjectMapper mapper = new ObjectMapper(); | |
final SampleData data = mapper.readValue(json, SampleData.class); | |
System.out.println(data.toString()); | |
} | |
} | |
class SampleData { | |
public String toString() { | |
return "SampleData [id=" + id + "]"; | |
} | |
public int id; | |
} |
Author
dmikurube
commented
Aug 30, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment