Solon v2.9.2

solon-serialization-properties

</> markdown
<dependency>
    <groupId>org.noear</groupId>
    <artifactId>solon-serialization-properties</artifactId>
</dependency>

1、描述

序列化扩展插件,(基于 sanck3 实现)为 Solon Serialization 提供类似 properties 和 jsonpath 格式参数的适配。可参数支持(v2.7.6 后支持):

  • ?user.id=1&user.name=noear&user.type[0]=a&user.type[1]=b&user.birthday=2020-01-01
  • ?type[]=a&type[]=b
  • ?order[id]=a

输出格式示例(properties 格式,通过前端指定头信息 "X-Serialization=@properties" 控制输出):

user.id=1
user.name=noear
user.type[0]=a
user.type[1]=b

2、主要接口实现类

实现接口备注
PropertiesRenderFactoryRenderFactory用于处理 properties 渲染输出
PropertiesActionExecutorActionExecuteHandler用于处理类似 properties 和 jsonpath 格式参数的请求

何时会被时用?当参数名带有 .[ 符号时会执行。

3、高级格式化定制(基于接口)

默认只处理 get 请求,如果需要包括 from-data 和 formUrlencoded 处理,需要配置:

@Configuration
public class Config {
    @Bean
    public void init(@Inject PropertiesActionExecutor executor){
        //允许 get 请求处理(默认为 true)
        executor.allowGet(true)
        
        //允许 post form 请求处理(默认为 false)
        executor.allowPostForm(false);
    }
}

3、个性化输出定制

public class User{
    public long id;
    public String name;
    public String[] type; 
    
    //格式化日期
    @ONodeAttr(format = "yyyy-MM-dd") //尽量不使用个性化定制//这样不会依赖具体框架
    public Date birthday;
}

public enum BookType {
    NOVEL(2,"小说"),
    CLASSICS(3,"名著");

    @ONodeAttr 
    public final int code; //使用 code 做为序列化的字段
    public final String des;
    BookType(int code, String des){this.code=code; this.des=des;}
}