-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create custom Jackson serializer and deserializer for new typed Metri…
…cType, change type output to lower case
- Loading branch information
Michael Burman
committed
Aug 26, 2015
1 parent
ee9f169
commit 4d07950
Showing
7 changed files
with
77 additions
and
24 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...i-common/src/main/java/org/hawkular/metrics/api/jaxrs/jackson/MetricTypeDeserializer.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,23 @@ | ||
package org.hawkular.metrics.api.jaxrs.jackson; | ||
|
||
import java.io.IOException; | ||
|
||
import org.hawkular.metrics.core.api.MetricType; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
|
||
/** | ||
* Created by miburman on 8/26/15. | ||
*/ | ||
public class MetricTypeDeserializer extends JsonDeserializer<MetricType<?>> { | ||
|
||
@Override public MetricType<?> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) | ||
throws IOException, JsonProcessingException { | ||
JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser); | ||
return MetricType.fromTextCode(jsonNode.get("type").asText()); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...api-common/src/main/java/org/hawkular/metrics/api/jaxrs/jackson/MetricTypeSerializer.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,23 @@ | ||
package org.hawkular.metrics.api.jaxrs.jackson; | ||
|
||
import java.io.IOException; | ||
|
||
import org.hawkular.metrics.core.api.MetricType; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
|
||
/** | ||
* Created by miburman on 8/26/15. | ||
*/ | ||
public class MetricTypeSerializer extends JsonSerializer<MetricType<?>> { | ||
|
||
@Override | ||
public void serialize(MetricType<?> metricType, JsonGenerator jsonGenerator, | ||
SerializerProvider serializerProvider) | ||
throws IOException, JsonProcessingException { | ||
jsonGenerator.writeString(metricType.getText()); | ||
} | ||
} |
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
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
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