-
Notifications
You must be signed in to change notification settings - Fork 550
Empty exposedPorts: ImmutableSet serialization not working as configured by docker-client, with Jackson 2.9.x #893
Comments
I have isolated dependency issue to Jackson (2.8.X doesn't show this behaviour). Could it be possible that Jackson 2.9.1 is not detecting the ImmutableSet of |
Can't isolate in stand-alone test with any version of Jackson. public class ImmutableSetIssue {
ImmutableSet<String> set = ImmutableSet.copyOf(Arrays.asList("a", "b", "c"));
@Test
public void containerConfig() throws IOException {
ObjectMapper om = new ObjectMapper();
ContainerConfig c = ContainerConfig.builder().exposedPorts(set).build();
ObjectNode on = (ObjectNode) om.readTree(om.writeValueAsString(c));
ArrayNode n = (ArrayNode) on.get("ExposedPorts");
assertEquals("a", n.get(0).asText());
assertEquals("b", n.get(1).asText());
assertEquals("c", n.get(2).asText());
}
} |
It seems there's a custom ImmutableSetSerializer. With it: private static class ImmutableSetSerializer extends JsonSerializer<ImmutableSet> {
@Override
public void serialize(final ImmutableSet value, final JsonGenerator jgen,
final SerializerProvider provider) throws IOException {
final Map map = (value == null) ? null : Maps.asMap(value, VOID_VALUE);
OBJECT_MAPPER.writeValue(jgen, map);
}
}
it seems /**
* Flag that indicates what to do with `null` values, distinct from
* handling of {@link #_suppressableValue}
*
* @since 2.9
*/
protected final boolean _suppressNulls; It's false in the MapSerializer member variable by default, but when instantiated from
it's |
I'm not sure I understand exactly what you’re trying to do or what is going wrong. So I apologize if this question is off the mark. But are you using |
With PublishAllPorts: true and ExposedPorts as rendered in 2.8.x ( |
Ok, I see. I wasn't aware of that combination of options. Could you give the snippet of code you’re using to set up your configs and create your container? |
I don't know if this is relevant at all, but in case this is something that needs to be refactored, I want to make a note about the In their swagger.yaml, This seems like almost the right thing to do, because I think the "map of values to empty objects" is an attempt to hack a set type into go; see https://github.com/deckarep/golang-set, a go library which makes a set type by doing this exact "map of whatever to an empty struct" thing, and which claims to be used in docker. But I don't know how our internal |
Yes, it looks like it's the case, ImmutableSet is probably not the right value for this - or, if it is, it should be mapped to a map of |
With regard to:
You have: private static class ImmutableSetSerializer extends JsonSerializer<ImmutableSet> {
@Override
public void serialize(final ImmutableSet value, final JsonGenerator jgen,
final SerializerProvider provider) throws IOException {
final Map map = (value == null) ? null : Maps.asMap(value, VOID_VALUE);
OBJECT_MAPPER.writeValue(jgen, map);
}
}
private static class ImmutableSetDeserializer extends JsonDeserializer<ImmutableSet> {
@Override
public ImmutableSet<?> deserialize(final JsonParser jp, final DeserializationContext ctxt)
throws IOException {
final Map map = OBJECT_MAPPER.readValue(jp, Map.class);
return (map == null) ? null : ImmutableSet.copyOf(map.keySet());
}
} in your ObjectMapperProvider.java, and you register these in the object mapper you use. |
Ah, yes, thank you. That's exactly what I was looking for but couldn't find. My guess is that changing the I pushed a change for this to a branch on my fork, 893-set-to-map on johnflavin/docker-client. Is it possible for you to build a jar from that and test it out? |
Yes, I could confirm that the issue goes away with the change in that branch. ExposedPorts is now properly filled:
|
Thanks for checking that out. I’ll clean this up and open a PR for it. |
Description
I am creating a container with the exposedPorts property filled. However, it's not being used:
I am checking thru the debugger however that the ContainerConfig contains the right set of values.
I have Jackson 2.9.1 and Jersey 2.25.1 in classpath, and I can't use lower versions because of other dependencies. My guess is that it's related to this... with older versions (docker-client 8.8.0, jackson 2.8.9, hk2-2.5.0-b38) it didn't happen.
The text was updated successfully, but these errors were encountered: