com.arakelian.jackson.MapPath Maven / Gradle / Ivy
The newest version!
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arakelian.jackson;
import java.io.IOException;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.immutables.value.Value;
import com.arakelian.jackson.MapPath.MapPathSerializer;
import com.arakelian.jackson.utils.JacksonUtils;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
@Value.Immutable
@JsonSerialize(using = MapPathSerializer.class, as = ImmutableMapPath.class)
@JsonDeserialize(builder = ImmutableMapPath.Builder.class)
public abstract class MapPath extends AbstractMapPath {
/**
* Customize serializer that prevents 'empty' MapPath objects from being serialized
*/
public static class MapPathSerializer extends StdSerializer {
public MapPathSerializer() {
super(MapPath.class);
}
@Override
public boolean isEmpty(final SerializerProvider provider, final MapPath value) {
// we don't want to serialize 'empty' MapPath objects
return value == null || value.getProperties().isEmpty();
}
@Override
public void serialize(final MapPath value, final JsonGenerator gen, final SerializerProvider provider)
throws IOException {
final Map © 2015 - 2025 Weber Informatics LLC | Privacy Policy