google / google/gson

Serialization dislocation

Open
#1,910 1 comment 0 reactions 0 assignees View on GitHub
bug needs-info
Dominant language
Java
Stars
24.2k
Forks
4.5k
Avg merge
6d 4h
Merged PRs (30d)
12

Description

## Dependency
JDK 1.8

```xml

com.google.code.gson
gson
2.8.6

```
## Usage
```java
(new GsonBuilder()).disableHtmlEscaping().setDateFormat("yyyy-MM-dd HH:mm:ss").serializeSpecialFloatingPointValues().create().toJson(obj)
```
The obj is `List` DTO like:
```java
public class DTO implements Serializable {

private int offlineActivityId;

private Date addTime;

private Date updateTime;

private int branchId;

private String branchName;

private int branchCount;

private String shopName;

private byte status;

//Omit other codes
}
```
## Appearance

**Sometimes**(not always)the result of Serialization is like this:
```json
[
{
"offlineActivityId":0,
"branchId":111111,
"branchName":"店",
"branchCount":0,
"shopName":"糕",
"status":0
},
{
"offlineActivityId":0,
"branchId":222222,
"branchName":"店",
"branchCount":0,
"shopName":"200",
"status":0
},
"糕",
{
"offlineActivityId":0,
"branchId":33333,
"branchName":"店",
"branchCount":0,
"shopName":"100",
"status":0
},
"糕",
{
"offlineActivityId":0,
"branchId":444444,
"branchName":"店",
"branchCount":0,
"shopName":"糕",
"status":0
}
]
```
you can see in some unit the value of branchCount is assigned to shopName,and the value of shopName appeares in a strange position

Is it a bug?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.