Skip to content

Commit

Permalink
fix(JSON): JSONify Java maps as JSON dicts
Browse files Browse the repository at this point in the history
  • Loading branch information
ettersi committed May 13, 2024
1 parent c1932ec commit 1b23910
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* Handles conversion of various data types to JSON.
Expand Down Expand Up @@ -49,7 +50,11 @@ public void write(JsonWriter out, T value) throws IOException {
if (Number.class.isAssignableFrom(type)) out.value((Number)((GenericValue)value).getValue());
else if (type.equals(String.class)) out.value((String)((GenericValue)value).getValue());
else if (type.equals(Boolean.class)) out.value((Boolean)((GenericValue)value).getValue());
else if (List.class.isAssignableFrom(type) || (type.isArray() && type.getComponentType().isPrimitive())) {
else if (
List.class.isAssignableFrom(type)
|| (type.isArray() && type.getComponentType().isPrimitive())
|| Map.class.isAssignableFrom(type)
) {
TypeAdapter delegate = gson.getAdapter(TypeToken.get(type));
Object v = ((GenericValue)value).getValue();
delegate.write(out, v);
Expand Down

0 comments on commit 1b23910

Please sign in to comment.