-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for enhancement #37 Create a way to get response JSON from a query.
- Loading branch information
Jeff Sabin
committed
Jun 19, 2015
1 parent
b56f311
commit 2427cde
Showing
5 changed files
with
181 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/org/kairosdb/client/DataPointTypeRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.kairosdb.client; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
|
||
public class DataPointTypeRegistry | ||
{ | ||
private Map<String, Class> customGroupTypes = new HashMap<String, Class>(); | ||
|
||
public DataPointTypeRegistry() | ||
{ | ||
customGroupTypes.put("number", Number.class); | ||
customGroupTypes.put("text", String.class); | ||
} | ||
|
||
public void registerCustomDataType(String groupType, Class dataPointClass) | ||
{ | ||
checkArgument(!customGroupTypes.containsKey(groupType), "Type has already been registered"); | ||
|
||
customGroupTypes.put(groupType, dataPointClass); | ||
} | ||
|
||
public Class getDataPointValueClass(String groupType) | ||
{ | ||
Class valueClass = customGroupTypes.get(groupType); | ||
return valueClass == null? Number.class : valueClass; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.kairosdb.client; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import org.kairosdb.client.deserializer.GroupByDeserializer; | ||
import org.kairosdb.client.deserializer.ResultsDeserializer; | ||
import org.kairosdb.client.response.GroupResult; | ||
import org.kairosdb.client.response.Results; | ||
|
||
import java.io.Reader; | ||
import java.lang.reflect.Type; | ||
|
||
public class JsonMapper | ||
{ | ||
private Gson mapper; | ||
|
||
public JsonMapper(DataPointTypeRegistry typeRegistry) | ||
{ | ||
GsonBuilder builder = new GsonBuilder(); | ||
builder.registerTypeAdapter(GroupResult.class, new GroupByDeserializer()); | ||
builder.registerTypeAdapter(Results.class, new ResultsDeserializer(typeRegistry)); | ||
mapper = builder.create(); | ||
|
||
|
||
} | ||
|
||
public <T> T fromJson(Reader json, Type typeOfT) | ||
{ | ||
return mapper.fromJson(json, typeOfT); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters