Skip to content

Instantly share code, notes, and snippets.

@dmikurube
Created August 30, 2017 08:16
Show Gist options
  • Save dmikurube/7ff6d073fbbf0e5f93e2d24e213514e2 to your computer and use it in GitHub Desktop.
Save dmikurube/7ff6d073fbbf0e5f93e2d24e213514e2 to your computer and use it in GitHub Desktop.
JacksonExp.java
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
}
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;
}
@dmikurube
Copy link
Author

SampleData [id=12345000]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment