
com.sap.cloud.sdk.result.ElementNameGsonFieldNamingStrategy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fluent-result Show documentation
Show all versions of fluent-result Show documentation
Fluent API for handling result structures.
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