@Override
    public void serialize(Asn1OutputStream out, Class<? extends Object> type, Object instance, Asn1ObjectMapper mapper)
            throws IOException {
        for (final Map.Entry<String, List<Asn1Field>> entry : fieldsMap(mapper.getFields(type)).entrySet()) {
            final List<Asn1Field> fields = entry.getValue();
            final Object[] values = new Object[fields.size()];
            if (!fetchValues(fields, instance, values)) continue;

            try (final Asn1OutputStream seqOut = new Asn1OutputStream(out, getNestedTagNo(type))) {
                try (final Asn1OutputStream oidOut = new Asn1OutputStream(seqOut, 0x06)) {
                    Asn1Utils.encodeObjectIdentifier(entry.getKey(), oidOut);
                }

                int i = 0;
                for (final Asn1Field field : fields) {
                    try (final Asn1OutputStream propOut = new Asn1OutputStream(seqOut, field.tagNo)) {
                        mapper.writeValue(propOut, field.converter(), field.type(), values[i++]);
                    }
                }
            }
        }
    }
@Test
    public void shouldSerializeWithOptional() {
        assertArrayEquals(
            new byte[] {
                0x30, 6, 0x06, 1, 44, 0x02, 1, 4, 0x30, 6, 0x06, 1, 83, 0x02, 1, 3,
                0x30, 9, 0x06, 1, 84, 0x02, 1, 1, 0x02, 1, 2
            },
            serialize(new SetOfIdentifiedConverter(), Set.class, new Set(1, 2, 3, 4))
        );
    }