All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sap.cloud.sdk.result.ElementNameGsonFieldNamingStrategy Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved.
 */

package com.sap.cloud.sdk.result;

import java.lang.reflect.Field;

import com.google.common.base.Strings;
import com.google.gson.FieldNamingStrategy;

/**
 * Implementation of GSON {@link FieldNamingStrategy} using the value from annotation {@link ElementName} when
 * serializing field names.
 */
public class ElementNameGsonFieldNamingStrategy implements FieldNamingStrategy
{
    @Override
    public String translateName( final Field field )
    {
        final ElementName annotation = field.getAnnotation(ElementName.class);
        final String name = field.getName();

        if( annotation == null ) {
            return name;
        }

        if( Strings.isNullOrEmpty(annotation.value()) ) {
            return name;
        }

        return annotation.value();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy