-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed serialization of typed values. Addressed issue #45
- Loading branch information
benni
committed
Dec 20, 2019
1 parent
b228bf2
commit 3d77934
Showing
5 changed files
with
85 additions
and
2 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
29 changes: 29 additions & 0 deletions
29
Commons/src/main/java/eu/neclab/ngsildbroker/commons/datatypes/TypedValue.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,29 @@ | ||
package eu.neclab.ngsildbroker.commons.datatypes; | ||
|
||
public class TypedValue { | ||
private String type; | ||
private Object value; | ||
|
||
|
||
|
||
|
||
public TypedValue(String type, Object value) { | ||
this.type = type; | ||
this.value = value; | ||
} | ||
public String getType() { | ||
return type; | ||
} | ||
public void setType(String type) { | ||
this.type = type; | ||
} | ||
public Object getValue() { | ||
return value; | ||
} | ||
public void setValue(Object value) { | ||
this.value = value; | ||
} | ||
|
||
|
||
|
||
} |
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
25 changes: 25 additions & 0 deletions
25
...ons/src/main/java/eu/neclab/ngsildbroker/commons/serialization/TypedValueGsonAdapter.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,25 @@ | ||
package eu.neclab.ngsildbroker.commons.serialization; | ||
|
||
import java.lang.reflect.Type; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonPrimitive; | ||
import com.google.gson.JsonSerializationContext; | ||
import com.google.gson.JsonSerializer; | ||
|
||
import eu.neclab.ngsildbroker.commons.constants.NGSIConstants; | ||
import eu.neclab.ngsildbroker.commons.datatypes.TypedValue; | ||
|
||
public class TypedValueGsonAdapter implements JsonSerializer<TypedValue> { | ||
|
||
|
||
@Override | ||
public JsonElement serialize(TypedValue src, Type typeOfSrc, JsonSerializationContext context) { | ||
JsonObject top = new JsonObject(); | ||
top.add(NGSIConstants.JSON_LD_TYPE, new JsonPrimitive(src.getType())); | ||
top.add(NGSIConstants.JSON_LD_VALUE, context.serialize(src.getValue())); | ||
return top; | ||
} | ||
|
||
} |
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