@Test public void testJsonCompact_notBecauseFieldValue() { CStructDescriptor descriptor = new CStructDescriptor( null, "test", "Test", ImmutableList.of( new CField(null, 1, PRequirement.OPTIONAL, "first", PPrimitive.STRING.provider(), null, null), new CField(null, 2, PRequirement.OPTIONAL, "second", PPrimitive.STRING.provider(), null, null) ), ImmutableMap.of("json.compact", "")); assertThat(descriptor.isJsonCompactible(), is(true)); CStruct.Builder builder = new CStruct.Builder(descriptor); builder.set(2, "second"); assertThat(builder.valid(), is(true)); CStruct struct = builder.build(); assertThat(struct.jsonCompact(), is(false)); }
@Override public boolean jsonCompact() { CStructDescriptor descriptor = descriptor(); if (!descriptor.isJsonCompactible()) { return false; } boolean missing = false; for (CField field : descriptor.getFields()) { if (has(field.getId())) { if (missing) { return false; } } else { missing = true; } } return true; }
CStruct implements CMessage<CStruct>, JsonCompactible { @Override public boolean jsonCompact() { CStructDescriptor descriptor = descriptor(); if (!descriptor.isJsonCompactible()) { return false; } boolean missing = false; for (CField field : descriptor.getFields()) { if (has(field.getId())) { if (missing) { return false; } } else { missing = true; } } return true; } }
CStruct implements CMessage<CStruct>, JsonCompactible { @Override public boolean jsonCompact() { CStructDescriptor descriptor = descriptor(); if (!descriptor.isJsonCompactible()) { return false; } boolean missing = false; for (CField field : descriptor.getFields()) { if (has(field.getId())) { if (missing) { return false; } } else { missing = true; } } return true; } private  CStruct(Builder builder); }
CStruct implements CMessage<CStruct>, JsonCompactible { @Override public boolean jsonCompact() { CStructDescriptor descriptor = descriptor(); if (!descriptor.isJsonCompactible()) { return false; } boolean missing = false; for (CField field : descriptor.getFields()) { if (has(field.getId())) { if (missing) { return false; } } else { missing = true; } } return true; } private  CStruct(Builder builder); Map<Integer,Object> values(); @Override boolean jsonCompact(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Nonnull @Override PMessageBuilder<CStruct,CField> mutate(); @Nonnull @Override CStructDescriptor descriptor(); }
CStruct implements CMessage<CStruct>, JsonCompactible { @Override public boolean jsonCompact() { CStructDescriptor descriptor = descriptor(); if (!descriptor.isJsonCompactible()) { return false; } boolean missing = false; for (CField field : descriptor.getFields()) { if (has(field.getId())) { if (missing) { return false; } } else { missing = true; } } return true; } private  CStruct(Builder builder); Map<Integer,Object> values(); @Override boolean jsonCompact(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Nonnull @Override PMessageBuilder<CStruct,CField> mutate(); @Nonnull @Override CStructDescriptor descriptor();  }