Skip to content

Commit

Permalink
fix: 3rd object support for docs gen
Browse files Browse the repository at this point in the history
  • Loading branch information
sakurawald committed Jul 22, 2024
1 parent f0ba61f commit e6fc7d0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
2 changes: 1 addition & 1 deletion fuji-fabric.wiki
48 changes: 25 additions & 23 deletions src/main/java/io/github/sakurawald/generator/JsonDocsGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,33 +79,35 @@ private void walk(Object obj, JsonObject root) {
}
}
root.add(fieldName, jsonArray);
} else {
if (Map.class.isAssignableFrom(field.getType())) {
root.addProperty(fieldName + SKIP_WALK, "map type");
JsonObject jsonObject = new JsonObject();
Map<?, ?> map = (Map<?, ?>) value;
for (Map.Entry<?, ?> entry : map.entrySet()) {
String mapKey = entry.getKey().toString();
Object mapValue = entry.getValue();
jsonObject.add(mapKey, gson.toJsonTree(mapValue));
}
root.add(fieldName, jsonObject);
} else if (Set.class.isAssignableFrom(field.getType())) {
root.addProperty(fieldName + SKIP_WALK, "set type");
JsonArray jsonArray = new JsonArray();
Set<?> set = (Set<?>) value;
for (Object elt : set) {
jsonArray.add(gson.toJsonTree(elt));
}
root.add(fieldName, jsonArray);
} else {
JsonObject jsonObject = new JsonObject();
walk(value, jsonObject);
root.add(fieldName, jsonObject);
} else if (Map.class.isAssignableFrom(field.getType())) {
root.addProperty(fieldName + SKIP_WALK, "map type");
JsonObject jsonObject = new JsonObject();
Map<?, ?> map = (Map<?, ?>) value;
for (Map.Entry<?, ?> entry : map.entrySet()) {
String mapKey = entry.getKey().toString();
Object mapValue = entry.getValue();
jsonObject.add(mapKey, gson.toJsonTree(mapValue));
}
root.add(fieldName, jsonObject);
} else if (Set.class.isAssignableFrom(field.getType())) {
root.addProperty(fieldName + SKIP_WALK, "set type");
JsonArray jsonArray = new JsonArray();
Set<?> set = (Set<?>) value;
for (Object elt : set) {
jsonArray.add(gson.toJsonTree(elt));
}
root.add(fieldName, jsonArray);
} else if (field.getType().getName().startsWith("com.mojang")) {
root.addProperty(fieldName + SKIP_WALK, "mojang type");
root.add(fieldName, gson.toJsonTree(value));
} else {
JsonObject jsonObject = new JsonObject();
walk(value, jsonObject);
root.add(fieldName, jsonObject);
}
}


} catch (IllegalAccessException e) {
Fuji.LOGGER.warn("failed to get the value of a field, {}", e.toString());
}
Expand Down

0 comments on commit e6fc7d0

Please sign in to comment.