-
Notifications
You must be signed in to change notification settings - Fork 3
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
Teeny json suport #3
Conversation
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.
Looks pretty good - just needs less TODOs and more JavaDoc :D
TeenyJson now can parse more complex JSONs like: {
"name": "Alex",
"age": 25,
"objectB": {
"name": "Jonathan",
"age": 30,
"objectC": {
"name": "John Doe",
"age": 23
}
},
"developer": true
} ObjectA objectA = new TeenyJson()
.readValue(json, ObjectA.class); Also collections List<ProductDto> products = new TeenyJson()
.readList(json, ProductDto.class); I should change |
… by itself, more tests.
…s now uses TeenyJson instead of Gson
src/main/java/net/jonathangiles/tools/teenyhttpd/implementation/ReflectionUtils.java
Outdated
Show resolved
Hide resolved
src/main/java/net/jonathangiles/tools/teenyhttpd/implementation/ReflectionUtils.java
Outdated
Show resolved
Hide resolved
src/main/java/net/jonathangiles/tools/teenyhttpd/implementation/ReflectionUtils.java
Outdated
Show resolved
Hide resolved
src/main/java/net/jonathangiles/tools/teenyhttpd/implementation/ReflectionUtils.java
Outdated
Show resolved
Hide resolved
src/main/java/net/jonathangiles/tools/teenyhttpd/implementation/ReflectionUtils.java
Outdated
Show resolved
Hide resolved
String baseName = method.getName().substring(3); | ||
|
||
Method accessorMethod; | ||
|
||
if (method.getParameterTypes()[0] == boolean.class) { | ||
accessorMethod = methodMap.get("is" + baseName); | ||
} else { | ||
accessorMethod = methodMap.get("get" + baseName); | ||
} | ||
|
||
if (accessorMethod != null) { | ||
JsonAlias jsonAlias = accessorMethod.getAnnotation(JsonAlias.class); | ||
|
||
if (jsonAlias != null) { | ||
return jsonAlias.value(); | ||
} | ||
} | ||
|
||
return method.getName().substring(3, 4).toLowerCase() | ||
+ method.getName().substring(4); |
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.
This is largely equivalent to the getFieldName
method above. I wonder if we could reduce the repetition?
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.
I moved the repeated code to:
private static String findAlias(Map<String, Method> methodMap, String baseName, Class<?> type) {
Method accessorMethod;
if (type == boolean.class) {
accessorMethod = methodMap.get("is" + baseName);
} else {
accessorMethod = methodMap.get("get" + baseName);
}
if (accessorMethod != null) {
JsonAlias jsonAlias = accessorMethod.getAnnotation(JsonAlias.class);
if (jsonAlias != null) {
return jsonAlias.value();
}
}
return null;
}
src/main/java/net/jonathangiles/tools/teenyhttpd/implementation/ReflectionUtils.java
Outdated
Show resolved
Hide resolved
* @return the parsed object which could be null. | ||
*/ | ||
@SuppressWarnings({"rawtypes", "unchecked"}) | ||
public <T, K> K readCollection(String json, Class<? extends Collection> collectionType, Class<T> type) { |
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.
Shouldn't the second parameter be Class<K extends Collection> collectionType
?
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.
Yes, but this may be the best choice:
public <T, K extends Collection> K readCollection(String json, Class<K> collectionType, Class<T> type)
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.
src/main/java/net/jonathangiles/tools/teenyhttpd/json/TeenyJson.java
Outdated
Show resolved
Hide resolved
… from code-review and a few changes.
@@ -25,6 +28,7 @@ jobs: | |||
run: mvn --batch-mode -DskipTests package | |||
|
|||
- name: Test | |||
timeout-minutes: 5 |
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.
Nice addition!
Do you want this merged now, or do you want to keep working on it? We also need to update the readme. |
…ation/deserialization
uff I didn't realize that there are a lot of cases, there is a few cases missing especially with collections an Maps, I believe to have a decent version this week |
Let me know when you want another review! |
Sorry for the late response, I've been sick these days. Yes please, another review would be awesome, I consider this PR can now be merged |
I'm back! I've been travelling and busy with work / life. I'll get to reviewing this today. |
Welcome back!, no problem I was also quite busy :P looking forward for new challenges |
Only very minor feedback - then we can merge. Thanks |
Co-authored-by: Jonathan Giles <[email protected]>
Co-authored-by: Jonathan Giles <[email protected]>
Removed @transient and java.desktop requirement, and created @JsonIgnore as replacement.
Usage: