Stabilize complex attributes by trask · Pull Request #7973 · open-telemetry/opentelemetry-java
Oh wait, I see. Its the difference between the top level representation. I still think you could centralize the logic all in ProtoJson by adding a int level parameter to append and changing the logic based on whether the level was 0 or non-0. Something like the following, demonstrated on DOUBLE but applicable to all the types:
static void append(StringBuilder sb, Value<?> value, int level) {
switch (value.getType()) {
case DOUBLE:
appendDouble(sb, (Double) value.getValue(), /*wrapWithQuotes*/ level > 0);
break;
// other cases omitted for brevity
}
}
private static void appendDouble(StringBuilder sb, double value, boolean wrapWithQuotes) {
if (wrapWithQuotes) {
sb.append('"');
}
if (Double.isNaN(value)) {
sb.append("NaN");
} else if (Double.isInfinite(value)) {
sb.append(value > 0 ? "Infinity" : "-Infinity");
} else {
sb.append(value);
}
if (wrapWithQuotes) {
sb.append('"');
}
}