This commit is contained in:
redkale
2024-06-02 07:56:21 +08:00
parent bea1900fdc
commit d8c13c8420
7 changed files with 45 additions and 9 deletions

View File

@@ -29,5 +29,6 @@ jobs:
- name: Build with Maven
run: mvn --batch-mode -e -X clean deploy -DskipTests=true
env:
MAVEN_GPG_KEY: aaaaaa
MAVEN_GPG_KEY: ${{ secrets.OSSRHGPGKEY }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.OSSRHGPGPASSWORD }}
MAVEN_GPG_KEY_FINGERPRINT: CD4C40E804D972E2569BF61A4E3BD7A9E43CC39E

View File

@@ -2,11 +2,10 @@
*/
package org.redkale.convert;
import java.lang.annotation.*;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;
import java.lang.annotation.*;
/**
* 依附在setter、getter方法、字段进行简单的配置 <br>
* 优先使用coder字段
@@ -42,7 +41,11 @@ public @interface ConvertCoder {
/**
* 序列化定制化的 Encodeable, 构造函数的参数可以是:<br>
* 1、ConvertFactory 2、Type 3、Class 4、ConvertFactory和Type 5、ConvertFactory和Class
* 1、ConvertFactory <br>
* 2、Type <br>
* 3、Class <br>
* 4、ConvertFactory和Type <br>
* 5、ConvertFactory和Class <br>
*
* <p>类如果存在instance单实例对象字段值则优先使用instance对象
*
@@ -52,7 +55,11 @@ public @interface ConvertCoder {
/**
* 反序列化定制化的 Decodeable, 构造函数的参数可以是:<br>
* 1、ConvertFactory 2、Type 3、Class 4、ConvertFactory和Type 5、ConvertFactory和Class
* 1、ConvertFactory <br>
* 2、Type <br>
* 3、Class <br>
* 4、ConvertFactory和Type <br>
* 5、ConvertFactory和Class <br>
*
* <p>类如果存在instance单实例对象字段值则优先使用instance对象
*

View File

@@ -5,11 +5,10 @@
*/
package org.redkale.convert;
import java.lang.annotation.*;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;
import java.lang.annotation.*;
/**
* 依附在setter、getter方法、字段进行简单的配置
*
@@ -51,6 +50,15 @@ public @interface ConvertColumn {
*/
ConvertType type() default ConvertType.ALL;
/**
* 字段值转换器
*
* @return ConvertColumnTransfer实现类
*
* @since 2.8.0
*/
Class<? extends ConvertColumnTransfer> tranfer() default ConvertColumnTransfer.class;
/**
* ConvertColumn 的多用类
*

View File

@@ -0,0 +1,16 @@
/*
*/
package org.redkale.convert;
import org.redkale.util.Attribute;
/**
*
* @author zhangjx
* @param <F> 字段类型
*/
public interface ConvertColumnTransfer<F> {
public <A> A transfer(Object obj, Attribute attribute, F value);
}

View File

@@ -106,6 +106,10 @@ public final class EnMember<W extends Writer, T, F> {
return new EnMember<>(attribute, factory.loadEncoder(fieldtype), null, null);
}
public F getFieldValue(T obj) {
return attribute.get(obj);
}
public final boolean accepts(String name) {
return attribute.field().equals(name);
}

View File

@@ -141,7 +141,7 @@ public abstract class Writer {
public void writeObjectField(final EnMember member, Object obj) {
Object value;
if (objFieldFunc == null) {
value = member.attribute.get(obj);
value = member.getFieldValue(obj);
} else {
value = objFieldFunc.apply(member.attribute, obj);
}

View File

@@ -414,7 +414,7 @@ public class ProtobufWriter extends Writer implements ByteTuple {
public void writeObjectField(final EnMember member, Object obj) {
Object value;
if (objFieldFunc == null) {
value = member.getAttribute().get(obj);
value = member.getFieldValue(obj);
} else {
value = objFieldFunc.apply(member.getAttribute(), obj);
}