-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #85: Marshal Duration config fields as milliseconds for easier …
…use in javascript.
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 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
34 changes: 34 additions & 0 deletions
34
src/main/java/com/github/mk23/jmxproxy/conf/DurationSerializer.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,34 @@ | ||
package com.github.mk23.jmxproxy.conf; | ||
|
||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
|
||
import io.dropwizard.util.Duration; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* <p>Custom serializer for configuration Duration fields.</p> | ||
* | ||
* Converts <code>io.dropwizard.util.Duration</code> types to milliseconds | ||
* for JSON requests. | ||
* | ||
* @see <a href="http://dropwizard.github.io/dropwizard/0.9.2/dropwizard-util/apidocs/io/dropwizard/util/Duration.html">io.dropwizard.util.Duration</a> | ||
* | ||
* @author mk23 | ||
* @since 2016-01-29 | ||
* @version 3.2.1 | ||
*/ | ||
public class DurationSerializer extends JsonSerializer<Duration> { | ||
/** {@inheritDoc} */ | ||
@Override | ||
public final void serialize( | ||
final Duration duration, | ||
final JsonGenerator jgen, | ||
final SerializerProvider provider | ||
) throws IOException, JsonProcessingException { | ||
jgen.writeNumber(duration.toMilliseconds()); | ||
} | ||
} |