Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
noear committed Jul 25, 2023
1 parent b4a2d44 commit 6f59332
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ options.addEncoder(Date.class, (data, node) -> {
String json = ONode.loadObj(orderModel, options).toJson();
```




## 关于序列化的特点
#### 对象(可以带type)
```json
Expand All @@ -200,6 +203,39 @@ String json = ONode.loadObj(orderModel, options).toJson();
[{"@type":"...","a":1,"b":"2"},{"@type":"...","a":2,"b":"10"}]
```

#### 序列化注解定制

```java
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;}
}

public class Book {
String name;
BookType type;
@ONodeAttr(serialize=false) String author; //不序列化
@ONodeAttr(format="yyyy-MM-dd") Date releaseTime; //格式化时间输出
}
```

#### 序列化编解码定制

```java
Options options = Options.def();
options.addEncoder(Date.class, (data, node) -> {
node.val().setString(DateUtil.format(data, "yyyy-MM-dd"));
});
options.addDecoder(Date.class, ...);

String json = ONode.loadObj(orderModel, options).toJson();
```

## 关于Json path的支持
* 字符串使用单引号,例:\['name']
* 过滤操作用空隔号隔开,例:\[?(@.type == 1)]
Expand Down

0 comments on commit 6f59332

Please sign in to comment.