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

Yaml serialization with JsonSubTypes and JsonTypeInfo #2989

Closed
shawkins opened this issue Apr 13, 2021 · 2 comments
Closed

Yaml serialization with JsonSubTypes and JsonTypeInfo #2989

shawkins opened this issue Apr 13, 2021 · 2 comments
Labels
Milestone

Comments

@shawkins
Copy link
Contributor

If you use the Serialization util to create yaml from an object that uses JsonSubTypes and JsonTypeInfo, the result will not be valid yaml:

package org.acme;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import io.fabric8.kubernetes.client.utils.Serialization;

public class Root {

    @JsonTypeInfo(
            use = JsonTypeInfo.Id.NAME,
            include = JsonTypeInfo.As.EXISTING_PROPERTY,
            property = "type"
    )
    @JsonSubTypes(
        @JsonSubTypes.Type(value = Typed.class, name = "x")
    )
    public interface Typeable {

        String getType();

    }

    public static class Typed implements Typeable {

        @Override
        public String getType() {
            return "x";
        }

    }

    private Typeable typeable;

    public Typeable getTypeable() {
        return typeable;
    }

    public void setTypeable(Typeable typeable) {
        this.typeable = typeable;
    }

    public static void main(String[] args) {
        Root root = new Root();
        root.setTypeable(new Typed());
        System.out.println(Serialization.asYaml(root));
    }

}

prints

---
typeable: !<x>
  type: "x"

This is covered in https://stackoverflow.com/questions/40272165/jackson-yaml-type-info-is-wrong-on-serialization and seems to require disabling a feature on the YAMLFactory.

shawkins added a commit to shawkins/kubernetes-client that referenced this issue Apr 13, 2021
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Apr 13, 2021
@manusa manusa added the bug label Apr 14, 2021
@manusa manusa added this to the 5.4.0 milestone Apr 14, 2021
@manusa
Copy link
Member

manusa commented May 7, 2021

Was this issue fixed by #2990 ? can we close it?

@shawkins
Copy link
Contributor Author

shawkins commented May 7, 2021

Yes it was fixed and can be closed.

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

No branches or pull requests

3 participants