Created
January 20, 2016 21:40
-
-
Save RaviH/bd770b5aedc9d8cf5fcb to your computer and use it in GitHub Desktop.
Example of how to deserialize json that starts with an array.
This file contains 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
package com.charter.aesd.activationlogin.edge.service | |
import com.charter.aesd.hystrix.utils.aws.CommandBuilderFactory | |
import com.fasterxml.jackson.databind.ObjectMapper | |
import groovy.json.JsonSlurper | |
import groovy.transform.ToString | |
/** | |
* Created by rhasija on 1/20/16. | |
*/ | |
class FooBar { | |
static String foo = """ | |
[ | |
{ | |
"name": "rao", | |
"last": "4545" | |
} | |
] | |
""" | |
static String fooWorks = """ | |
{"foos" : [ | |
{ | |
"name": "rao", | |
"last": "4545" | |
} | |
] | |
} | |
""" | |
public static void main(String[] args) { | |
def text = new JsonSlurper().parseText(foo) | |
def factory = CommandBuilderFactory.applyDefaults(new ObjectMapper()) | |
// factory.deserializationConfig.with(Des) | |
def fin = factory.readValue(foo, Foo[]) | |
println(fin) | |
} | |
} | |
@ToString | |
class Foo { | |
String name | |
String last | |
} | |
@ToString | |
class Def { | |
List<Foo> foos | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment