Este repositório foi arquivado em 2025-08-14. Você pode visualizar arquivos e cloná-lo, mas não pode fazer alterações, tais como push, abrir issues, pull requests ou comentários.
AutoWhitelist/src/main/java/com/awakenedredstone/autowhitelist/mixin/jankson/POJODeserializerMixin.java
2025-03-25 14:21:45 -03:00

31 linhas
1,6 KiB
Java

package com.awakenedredstone.autowhitelist.mixin.jankson;
import blue.endless.jankson.annotation.SerializedName;
import blue.endless.jankson.impl.POJODeserializer;
import com.awakenedredstone.autowhitelist.config.source.annotation.NameFormat;
import com.awakenedredstone.autowhitelist.config.source.annotation.SkipNameFormat;
import com.google.common.base.CaseFormat;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Local;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import java.lang.reflect.Field;
@Mixin(value = POJODeserializer.class, remap = false)
public class POJODeserializerMixin {
@ModifyExpressionValue(method = "unpackField", at = @At(value = "INVOKE", target = "Ljava/lang/reflect/Field;getName()Ljava/lang/String;"))
private static String parseName(String original, @Local(argsOnly = true) Object parent, @Local(argsOnly = true) Field field) {
NameFormat defaultNameFormat = parent.getClass().getAnnotation(NameFormat.class);
NameFormat nameFormat = field.getAnnotation(NameFormat.class);
SkipNameFormat skipNameFormat = field.getAnnotation(SkipNameFormat.class);
SerializedName nameAnnotation = field.getAnnotation(SerializedName.class);
if (skipNameFormat == null && (nameFormat != null || defaultNameFormat != null) && nameAnnotation == null) {
NameFormat formatter = nameFormat != null ? nameFormat : defaultNameFormat;
return CaseFormat.LOWER_CAMEL.to(formatter.value().getCaseFormat(), original);
}
return original;
}
}