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

io.bitsensor.lib.jackson.protobuf.PropertyNamingStrategyWrapper Maven / Gradle / Ivy

The newest version!
package io.bitsensor.lib.jackson.protobuf;

import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.PropertyNamingStrategy.PropertyNamingStrategyBase;
import io.bitsensor.proto.shaded.com.google.common.base.CaseFormat;


public class PropertyNamingStrategyWrapper extends PropertyNamingStrategyBase {
    private static final PropertyNamingStrategyBase SNAKE_TO_CAMEL = new SnakeToCamelNamingStrategy();
    private final PropertyNamingStrategyBase delegate;

    public PropertyNamingStrategyWrapper(PropertyNamingStrategy delegate) {
        if (delegate instanceof PropertyNamingStrategyBase) {
            this.delegate = (PropertyNamingStrategyBase) delegate;
        } else {
            this.delegate = SNAKE_TO_CAMEL;
        }

    }

    public String translate(String fieldName) {
        return this.delegate.translate(fieldName);
    }

    private static class SnakeToCamelNamingStrategy extends PropertyNamingStrategyBase {
        private SnakeToCamelNamingStrategy() {
        }

        public String translate(String fieldName) {
            return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, fieldName);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy