New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix JSON sources to convert to Lists and other types #664
Conversation
…easance as forgetting Spotless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for intruding, but since I was working on the Json support I wanted to chime in.
I believe that this approach is a bit strict and it has a dependency on Jackson.
Jackson has support for converting to a generic type with the help of its JavaType
. This JavaType
can be constructed from a java.lang.reflect.Type
.
This means that new methods (or the existing methods) of the Node
can look like:
<T> T toType(Type type);
Object value(Type typeHint);
Everything in the end delegates to toType(Type)
which is implemented in the following way:
@Override
public <T> T toType(Type type) {
try {
return objectMapper.treeToValue(node, objectMapper.constructType(type));
}
catch (JsonProcessingException e) {
throw new UncheckedIOException("Failed to convert to type " + type, e);
}
}
As a final step all the places that were invoking the toType
and value
methods can be changed from doing Parameter#getType
to Parameter#getParameterizedType
.
There won't be a need to have a custom argument converter and it would be possible to map into things like Map<String, Poem>
or List<Map<String, Poem>>
etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation looks as I would expect now @Michael1993.
I've left some comments about some more general confusions I have.
One thing that you should decide within the team is the breaking change in Node.java
. From my point of view it is fine to do that change, since this is a new interface and I really doubt that someone has implemented an entire new JSON parsing on top of JUnit Pioneer without contributing it back.
src/main/java/org/junitpioneer/jupiter/json/AbstractJsonArgumentsProvider.java
Outdated
Show resolved
Hide resolved
src/test/java/org/junitpioneer/jupiter/json/ArrayNodeToListTests.java
Outdated
Show resolved
Hide resolved
src/test/java/org/junitpioneer/jupiter/json/ArrayNodeToListTests.java
Outdated
Show resolved
Hide resolved
This PR contains no breaking changes as all classes/interfaces modified are package-private. |
I didn't notice that. They used to be public when I wrote them initially |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I understand all those reflection things it looks good to me, but I mostly trust @filiphr. When I have a look at the documentation I think there's no need in updating it. But please have a second look at it @Michael1993
Adding merge-ready to trigger full build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot Michael for working on this!
I only have two "take it or leave it" comments. In addition, do you think it make sense to add an example to the docs/demos?
Closes #654
Proposed commit message:
PR checklist
The following checklist shall help the PR's author, the reviewers and maintainers to ensure the quality of this project.
It is based on our contributors guidelines, especially the "writing code" section.
It shall help to check for completion of the listed points.
If a point does not apply to the given PR's changes, the corresponding entry can be simply marked as done.
Documentation (general)
.adoc
file in thedocs
folder, e.g.docs/report-entries.adoc
.adoc
file references demo insrc/demo/java
instead of containing code blocks as text.adoc
files)Documentation (new extension)
docs/docs-nav.yml
navigation has an entry for the new extensionpackage-info.java
contains information about the new extensionCode
Contributing
README.md
mentions the new contribution (real name optional)