package io.leangen.graphql.metadata.strategy.input;

import com.google.gson.FieldNamingPolicy;
import com.google.gson.FieldNamingStrategy;

import java.lang.reflect.Field;

/**
 * Created by bojan.tomic on 5/25/16.
 */
public class GsonFieldNamingStrategy implements FieldNamingStrategy {

    private FieldNameGenerator fieldNameGenerator;
    private FieldNamingStrategy fallback;

    public GsonFieldNamingStrategy() {
        this(new AnnotationBasedFieldNameGenerator(), FieldNamingPolicy.IDENTITY);
    }

    public GsonFieldNamingStrategy(FieldNameGenerator fieldNameGenerator, FieldNamingStrategy fallback) {
        this.fieldNameGenerator = fieldNameGenerator;
        this.fallback = fallback;
    }

    @Override
    public String translateName(Field field) {
        return fieldNameGenerator.generateFieldName(field).orElse(fallback.translateName(field));
    }
}

@@ -131,16 +131,59 @@
 trategy;
+%0Aimport io.leangen.graphql.util.ClassUtils;
 %0A%0Aimport
@@ -207,16 +207,43 @@
 t.Field;
+%0Aimport java.util.Optional;
 %0A%0A/**%0A *
@@ -900,47 +900,404 @@
 eld)
-.orElse(fallback.translateName(field));
+%0A                .orElse(nameFromGetter(field)%0A                        .orElse(fallback.translateName(field)));%0A    %7D%0A%0A    private Optional%3CString%3E nameFromGetter(Field field) %7B%0A        try %7B%0A            return fieldNameGenerator.generateFieldName(ClassUtils.findGetter(field.getType(), field.getName()));%0A        %7D catch (NoSuchMethodException e) %7B%0A            return Optional.empty();%0A        %7D
 %0A   

Fix deserialization with annotated getters