aboutsummaryrefslogtreecommitdiffstats
path: root/metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/model/json/JacksonUtil.java
diff options
context:
space:
mode:
Diffstat (limited to 'metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/model/json/JacksonUtil.java')
-rw-r--r--metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/model/json/JacksonUtil.java19
1 files changed, 14 insertions, 5 deletions
diff --git a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/model/json/JacksonUtil.java b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/model/json/JacksonUtil.java
index 4ac2cc4dec8..c4f2b7198a4 100644
--- a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/model/json/JacksonUtil.java
+++ b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/model/json/JacksonUtil.java
@@ -19,6 +19,12 @@ import java.util.Locale;
*/
public class JacksonUtil {
+ private static final DecimalFormat decimalFormat = createDecimalFormat();
+ private static DecimalFormat createDecimalFormat() {
+ DecimalFormat df = new DecimalFormat("#.####", new DecimalFormatSymbols(Locale.ENGLISH));
+ df.setMaximumFractionDigits(13);
+ return df;
+ }
/**
* Returns an object mapper with a custom floating point serializer to avoid scientific notation
*/
@@ -30,14 +36,17 @@ public class JacksonUtil {
mapper.registerModule(module);
return mapper;
}
+ /**
+ * Returns an object mapper with a custom floating point serializer to avoid scientific notation
+ */
+ public static void writeDouble(JsonGenerator jgen, Double value) throws IOException {
+ jgen.writeNumber(decimalFormat.format(value));
+ }
public static class DoubleSerializer extends JsonSerializer<Double> {
@Override
- public void serialize(Double value, JsonGenerator jgen,
- SerializerProvider provider) throws IOException {
- DecimalFormat df = new DecimalFormat("#.####", new DecimalFormatSymbols(Locale.ENGLISH));
- df.setMaximumFractionDigits(13);
- jgen.writeNumber(df.format(value));
+ public void serialize(Double value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
+ writeDouble(jgen, value);
}
}