Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeSignature.EXCLUDE It doesn't work. #280

Open
R2DA22 opened this issue Oct 25, 2024 · 3 comments
Open

TypeSignature.EXCLUDE It doesn't work. #280

R2DA22 opened this issue Oct 25, 2024 · 3 comments

Comments

@R2DA22
Copy link

R2DA22 commented Oct 25, 2024

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}}

@zapov
Copy link
Member

zapov commented Oct 28, 2024

Tnx for the bug report. I would guess this got broken at one point in time :(

@R2DA22
Copy link
Author

R2DA22 commented Oct 28, 2024

Could you please let me know when you expect to have this issue resolved?

@zapov
Copy link
Member

zapov commented Nov 5, 2024

Its hard to tell. I don't have as much time to work on this as before. So most likely sometimes early next year.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants