Skip to content

Commit

Permalink
Merge pull request #120 from fauna/improv-query-tags-deser
Browse files Browse the repository at this point in the history
Use cleaner impl for query tags deser
  • Loading branch information
findgriffin authored Aug 26, 2024
2 parents 7b2ff87 + 987ad03 commit 9ad8181
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/main/java/com/fauna/codec/json/QueryTagsDeserializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

import java.io.IOException;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

public class QueryTagsDeserializer extends JsonDeserializer<Map<String, String>> {
@Override
Expand All @@ -19,18 +21,16 @@ public Map<String,String> deserialize(JsonParser jp, DeserializationContext dese
case VALUE_NULL:
return null;
case VALUE_STRING:
var raw = jp.getValueAsString();
Map<String, String> ret = new HashMap<>();
if (raw.isEmpty()) {
return ret;
}
var rawString = jp.getValueAsString();

String[] tagPairs = jp.getValueAsString().split(",");
for (String tagPair : tagPairs) {
String[] tokens = tagPair.split("=");
ret.put(tokens[0], tokens[1]);
if (rawString.isEmpty()) {
return Map.of();
}
return ret;

return Arrays.stream(rawString.split(","))
.map(queryTag -> queryTag.split("="))
.filter(parts -> parts.length >= 2)
.collect(Collectors.toMap(t -> t[0], t -> t[1]));
default:
throw new JsonParseException(jp, MessageFormat.format("Unexpected token `{0}` deserializing query tags", jp.currentToken()));
}
Expand Down

0 comments on commit 9ad8181

Please sign in to comment.