JsonClassPathSource support generics type?
See original GitHub issueHello. I’ve tried the demo below but it doesn’t work. I think JsonClassPathSource
can’t deserialize json array to java list. Is there any other way to implement it? Thanks.
Java code:
@JsonClassPathSource("test.json")
void test(List<Person> persons){
log.info("{}",persons)
}
Json file:
[
{
"name": "a",
"age": 23
},
{
"name": "a",
"age": 23
}
]
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
JSON and Generics in Java - Type safety warning
it extends HashMap but doesn't support parameter type, if its definition is public class JSONObject<K,V> extends HashMap<K,V>.
Read more >Super Type Tokens in Java Generics - Baeldung
In this tutorial, we're going to get familiar with super type tokens and see how they can help us to preserve generic type...
Read more >Help me write a Play Json format for generic (bounded types ...
I am trying to write a play Json formatter for the enum and classes below. I want to de-serialize a Json file to...
Read more >Using generics to load any kind of Codable data
We added a Bundle extension for loading one specific type of JSON data from our app bundle, but now we have a second...
Read more >Example Using Generic (JSON) Resource Objects - Bloomreach
Resource is the primary object representation to solve all the complex integration problems in a generic way. So, the interface was designed to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Oh, yeah, I see where the problem is - you pass a list of objects to your test that expects a list of lists. See, when you execute a parameterized test, it expects an input (a list) which it converts to single parameters. In your example your parameter is a list, so the test tries to convert your input to a list but it can not do that because you supplied a simple list not a list of lists.
To demonstrate with an example, this should work:
Jedi list:
Note that I used two square brackets
[ ]
in my JSON file - because I want to pass a list of lists.i want use
@JsonClasspathSource
to prepare my integrate test data. i would like to write data to json file. it’s a complex struct. maybe single object or list. then. i will use injected object(list) to do test. my first idea is i write a utils to load data and deserialize to object. but i found@JsonClasspathSource
so i use it to prepare my complex test data.