Skip to content

Instantly share code, notes, and snippets.

@RaviH
Created January 20, 2016 21:40
Show Gist options
  • Save RaviH/bd770b5aedc9d8cf5fcb to your computer and use it in GitHub Desktop.
Save RaviH/bd770b5aedc9d8cf5fcb to your computer and use it in GitHub Desktop.
Example of how to deserialize json that starts with an array.
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