-
Notifications
You must be signed in to change notification settings - Fork 110
Open
Description
Hi, I'm facing a problem while serializing a JSON object using the library. The object has an interface as one of its attributes, and I've tried to suppress the $type in the serialized output with the @CompiledJson(typeSignature = CompiledJson.TypeSignature.EXCLUDE)
annotation, but it's not having the desired effect.
Here's a code sample to illustrate:
package org.example;
import com.dslplatform.json.*;
import com.dslplatform.json.runtime.Settings;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
DslJson<Object> dslJson = new DslJson<>(Settings.withRuntime().includeServiceLoader());
JsonWriter writer = dslJson.newWriter();
Model instance = new Model();
instance.iface = new WithCustomCtor(5);
dslJson.serialize(writer, instance);
System.out.println(writer);
}
@CompiledJson(typeSignature = CompiledJson.TypeSignature.EXCLUDE)
static class Model {
@JsonAttribute(typeSignature = CompiledJson.TypeSignature.EXCLUDE)
public Interface iface;
}
@CompiledJson(typeSignature = CompiledJson.TypeSignature.EXCLUDE)
public interface Interface {
void x(int v);
int x();
}
public static class WithCustomCtor implements Interface {
private int x;
@CompiledJson(typeSignature = CompiledJson.TypeSignature.EXCLUDE)
public WithCustomCtor(int x) {
this.x = x;
}
@Override
public void x(int v) {
x = v;
}
@Override
public int x() {
return x;
}
}
}
Result:
{"iface":{"$type":"org.example.Main.WithCustomCtor","x":5}}
Metadata
Metadata
Assignees
Labels
No labels