@Override public boolean isEmpty(SerializerProvider prov, Map<?, ?> value) { if (value.isEmpty()) { return true; } // 05-Nove-2015, tatu: Simple cases are cheap, but for recursive // emptiness checking we actually need to see if values are empty as well. Object supp = _suppressableValue; if ((supp == null) && !_suppressNulls) { return false; } JsonSerializer<Object> valueSer = _valueSerializer; final boolean checkEmpty = (MARKER_FOR_EMPTY == supp); if (valueSer != null) { for (Object elemValue : value.values()) { if (elemValue == null) { if (_suppressNulls) { continue; } return false; } if (checkEmpty) { if (!valueSer.isEmpty(prov, elemValue)) { return false; } } else if ((supp == null) || !supp.equals(value)) { return false; } } return true; } // But if not statically known, try this: for (Object elemValue : value.values()) { if (elemValue == null) { if (_suppressNulls) { continue; } return false; } try { valueSer = _findSerializer(prov, elemValue); } catch (JsonMappingException e) { // Ugh... can not just throw as-is, so... // 05-Nov-2015, tatu: For now, probably best not to assume empty then return false; } if (checkEmpty) { if (!valueSer.isEmpty(prov, elemValue)) { return false; } } else if ((supp == null) || !supp.equals(value)) { return false; } } return true; }
@Override public void serialize(Map<?, ?> value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException { jgen.writeStartObject(); if (!value.isEmpty()) { if (provider.isEnabled(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS)) { value = _orderEntries(value); } if (_valueSerializer != null) { serializeFieldsUsing(value, jgen, provider, _valueSerializer); } else { serializeFields(value, jgen, provider); } } jgen.writeEndObject(); }
@Override public void serializeWithType( Map<?, ?> value, JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer) throws IOException, JsonGenerationException { typeSer.writeTypePrefixForObject(value, jgen); if (!value.isEmpty()) { if (provider.isEnabled(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS)) { value = _orderEntries(value); } if (_valueSerializer != null) { serializeFieldsUsing(value, jgen, provider, _valueSerializer); } else { serializeFields(value, jgen, provider); } } typeSer.writeTypeSuffixForObject(value, jgen); }
@Override public void serialize(Map<?, ?> value, JsonGenerator gen, SerializerProvider provider) throws IOException { gen.writeStartObject(value); if (!value.isEmpty()) { if (_sortKeys || provider.isEnabled(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS)) { value = _orderEntries(value, gen, provider); } PropertyFilter pf; if ((_filterId != null) && (pf = findPropertyFilter(provider, _filterId, value)) != null) { serializeFilteredFields(value, gen, provider, pf, _suppressableValue); } else if ((_suppressableValue != null) || _suppressNulls) { serializeOptionalFields(value, gen, provider, _suppressableValue); } else if (_valueSerializer != null) { serializeFieldsUsing(value, gen, provider, _valueSerializer); } else { serializeFields(value, gen, provider); } } gen.writeEndObject(); }
@Override public void serializeWithType( Map<?, ?> value, JsonGenerator gen, SerializerProvider provider, TypeSerializer typeSer) throws IOException { typeSer.writeTypePrefixForObject(value, gen); // [databind#631]: Assign current value, to be accessible by custom serializers gen.setCurrentValue(value); if (!value.isEmpty()) { if (_sortKeys || provider.isEnabled(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS)) { value = _orderEntries(value, gen, provider); } PropertyFilter pf; if ((_filterId != null) && (pf = findPropertyFilter(provider, _filterId, value)) != null) { serializeFilteredFields(value, gen, provider, pf, _suppressableValue); } else if ((_suppressableValue != null) || _suppressNulls) { serializeOptionalFields(value, gen, provider, _suppressableValue); } else if (_valueSerializer != null) { serializeFieldsUsing(value, gen, provider, _valueSerializer); } else { serializeFields(value, gen, provider); } } typeSer.writeTypeSuffixForObject(value, gen); }
@Override public boolean isEmpty(Map<?, ?> value) { return (value == null) || value.isEmpty(); }