com.accessgatelabs.oss.builder.exceptions.LowerCamelCaseClassNameResolver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of response-builder Show documentation
Show all versions of response-builder Show documentation
AccessGate Labs Response Builder
/*
* Copyright 2020 the original author or authors.
*
* Licensed 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
*
* https://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.accessgatelabs.oss.builder.exceptions;
import org.springframework.util.StringUtils;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.jsontype.impl.TypeIdResolverBase;
/**
* The class that extends @see TypeIdResolverBase and
* overrides to provide Lower Camel Case Class Name for JSON
* outputs.
*
* @author Ekansh Tiwari
* @version 1.0.0
* @since 2020-06-02
* @see AccessGate Labs Response Builder on GitHub
* @see MIT License
*/
public class LowerCamelCaseClassNameResolver extends TypeIdResolverBase {
@Override
public String idFromValue(Object value) {
String capitalizedValue = StringUtils.capitalize(value.getClass().getSimpleName());
capitalizedValue = Character.toLowerCase(capitalizedValue.charAt(0)) + capitalizedValue.substring(1);
return capitalizedValue;
}
@Override
public String idFromValueAndType(Object value, Class> suggestedType) {
return idFromValue(value);
}
@Override
public JsonTypeInfo.Id getMechanism() {
return JsonTypeInfo.Id.CUSTOM;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy