FasterXML / FasterXML/jackson-databind

Make it possible to use `@JsonPropertyOrder` to order properties last (not just first)

オープン
#2,260 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る
主要言語
Java
スター
3.7k
フォーク
1.5k
平均マージ
3日 6時間
マージ済み PR(30日)
28

説明

While using `@JsonPropertyOrder` works for many cases, in one scenario, where I need to unwrap `Map`, (since `@JsonUnwrapped` doesn't work), leveraging `@JsonAnyGetter` does the trick. The side effect is that property ordering doesn't work.

If we could put a set of properties at the bottom perhaps with a `tail` option:

```
@JsonPropertyOrder(value= {"attributes", "resource", "resources", "embedded"}, tail={"links", "templates", "metadata" })
```
This would make it possible to serialize every attribute of the "attributes" map BEFORE serializing the `links`, `templates`, and `metadata`.

An alternative would be to make the `@JsonAnyGetter` still obey ordering from the "named" attribute, but I don't know if that is flat out impossible.

The original object is this one (with boilerplate removed for this issue), used to serialize various formats. The latest addition is the "attributes" `Map` at the top which can't be unwrapped:

```
@JsonPropertyOrder({ "attributes", "resource", "resources", "embedded", "links", "templates", "metadata" })
public class HalFormsDocument {

@JsonInclude(Include.NON_NULL) //
private Map attributes;

@JsonUnwrapped //
@JsonInclude(Include.NON_NULL) //
private T resource;

@JsonInclude(Include.NON_EMPTY) @JsonIgnore //
private Collection resources;

@JsonProperty("_embedded") //
@JsonInclude(Include.NON_EMPTY) //
private Map embedded;

@JsonProperty("page") //
@JsonInclude(Include.NON_NULL) //
private PagedResources.PageMetadata pageMetadata;

@JsonProperty("_links") //
@JsonInclude(Include.NON_EMPTY) //
@JsonSerialize(using = HalLinkListSerializer.class) //
@JsonDeserialize(using = HalFormsLinksDeserializer.class) //
private Links links;

@JsonProperty("_templates") //
@JsonInclude(Include.NON_EMPTY) //
private Map templates;

...
}
```
My test case produces this:

```
{
"_links" : {
"self" : {
"href" : "/employees/1"
}
},
"_templates" : {
"default" : {
"title" : null,
"method" : "post",
"contentType" : "",
"properties" : [ {
"name" : "name",
"required" : true
} ]
}
},
"name" : "Frodo Baggins"
}
```

instead of...

```
{
"name" : "Frodo Baggins",
"_links" : {
"self" : {
"href" : "/employees/1"
}
},
"_templates" : {
"default" : {
"title" : null,
"method" : "post",
"contentType" : "",
"properties" : [ {
"name" : "name",
"required" : true
} ]
}
}
}
```

While technically equivalent the former is much harder to read than the latter.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。