Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix remove duplicated list elements when size are same, for issue #2944 #2973

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public void accept(T object, Object value) {
}

Collection values = (Collection) value;

if (values.size() == collection.size()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个逻辑不对吧??

return;
}

for (Object item : values) {
if (item == null) {
collection.add(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.alibaba.fastjson2.issues_2900;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Issue2944 {
@Test
public void test() {
List<Employee> employees = new ArrayList<>();
employees.add(new Employee(0, "John"));
employees.add(new Employee(1, "Jane"));
employees.add(new Employee(2, "Bob"));
Department department = new Department("dev", employees);

String payload = JSON.toJSONString(department);
JSONObject jsonObject = JSON.parseObject(payload);
Department parsed = jsonObject.toJavaObject(Department.class);
assertEquals(payload, JSON.toJSONString(parsed));
}

class Department {
private final String name;
private final List<Employee> employees;

public String getName() {
return name;
}

public List<Employee> getEmployees() {
return employees;
}

public Department(String name, List<Employee> employees) {
this.name = name;
this.employees = employees;
}

@Override
public String toString() {
return "Department{" +
"name='" + name + '\'' +
", employees=" + employees +
'}';
}
}

class Employee {
private final Integer id;
private final String name;

public Integer getId() {
return id;
}

public String getName() {
return name;
}

public Employee(int id, String name) {
this.id = id;
this.name = name;
}

@Override
public String toString() {
return "Employee{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}
}
Loading