Skip to content
This repository has been archived by the owner on Nov 6, 2018. It is now read-only.

default to @JsonInclude(Include.NON_EMPTY) instead? #154

Open
jstrachan opened this issue Aug 11, 2016 · 9 comments
Open

default to @JsonInclude(Include.NON_EMPTY) instead? #154

jstrachan opened this issue Aug 11, 2016 · 9 comments

Comments

@jstrachan
Copy link
Contributor

when we generate YAML or JSON the output includes loads of empty values, lists, maps which looks kinda ugly.

Is there any reason we've gone with NON_NULL rather than the leaner NON_EMTPY?

@jimmidyson
Copy link
Contributor

There was a reason... It may have had to do with the jsonschema2pojo plugin, couldn't override it possibly. Maybe.

We should be able to override it on the object mapper though, might be easier that way.

@jstrachan
Copy link
Contributor Author

jstrachan commented Aug 11, 2016

so far all my attempts at overriding it on the serializer have failed - I tried that first before raising this issue :(

@jstrachan
Copy link
Contributor Author

FWIW if I lose all ordering I can disable the empty rendering...

        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
        objectMapper.disable(MapperFeature.USE_ANNOTATIONS);

by disabling all annotations; but then I lose all those nice ordering annotations :(

jstrachan added a commit to jstrachan/fabric8 that referenced this issue Aug 11, 2016
@jstrachan
Copy link
Contributor Author

I've figured out a hacky way around the problem. Marshal to YAML, parse as a JsonNode, recursively remove all empty values, then marshal again (to then avoid seeing the NOT_NULL annotations). Hack!!!
https://github.com/jstrachan/fabric8/blob/e0e8b1e7befea2d23f5a7988f53a9baf95cab1e5/components/kubernetes-api/src/main/java/io/fabric8/kubernetes/api/KubernetesHelper.java#L2193-L2254

would love to delete this code one day! :)

@jstrachan
Copy link
Contributor Author

actually 2 entities which we want to keep the NON_NULL is for ConfigMap and Secret (or TBH any field called data really)

@jimmidyson
Copy link
Contributor

Why do you want them to be non-null & not non-empty? Empty maps seem a bit useless?

@jstrachan
Copy link
Contributor Author

Empty string data values in a ConfigMap get removed from the map with NON_Empty - which breaks a pod using valueFrom to map the entry to an env var

@jimmidyson
Copy link
Contributor

Ah OK. So if you want to do this override propertyInclusion in KubernetesTypeAnnotator.

@jimmidyson
Copy link
Contributor

I'm out next week so if you fancy doing it, go for it, otherwise easy enough to do when I'm back.

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

No branches or pull requests

2 participants