fastjson serialization problem: Comparison method violates its general contract

Fastjson serialization problem: Comparison method violates its general contract
problem reappears
When testing the interface today, I called the Mybatis Plus paging query interface, and then converted the query result into a Json string, and reported this error:

java.lang.IllegalArgumentException: `Comparison method violates its general contract`!
	at java.util.TimSort.mergeHi(TimSort.java:899)
	at java.util.TimSort.mergeAt(TimSort.java:516)
	at java.util.TimSort.mergeForceCollapse(TimSort.java:457)
	at java.util.TimSort.sort(TimSort.java:254)
	at java.util.Arrays.sort(Arrays.java:1438)
	at com.alibaba.fastjson.util.TypeUtils.computeGetters(TypeUtils.java:1880)
	at com.alibaba.fastjson.util.TypeUtils.buildBeanInfo(TypeUtils.java:1820)
	at com.alibaba.fastjson.serializer.SerializeConfig.createJavaBeanSerializer(SerializeConfig.java:113)
	at com.alibaba.fastjson.serializer.SerializeConfig.getObjectWriter(SerializeConfig.java:821)
	at com.alibaba.fastjson.serializer.SerializeConfig.getObjectWriter(SerializeConfig.java:440)
	at com.alibaba.fastjson.serializer.JSONSerializer.getObjectWriter(JSONSerializer.java:448)
	at com.alibaba.fastjson.serializer.JSONSerializer.write(JSONSerializer.java:309)
	at com.alibaba.fastjson.JSON.toJSONString(JSON.java:793)
	at com.alibaba.fastjson.JSON.toJSONString(JSON.java:727)

Analysis:
The general meaning is: when fastjson was doing the conversion, it called the timsort sorting algorithm, and an error occurred during integration. But the more specific reason has never been understood, because this error is not inevitable.
A colleague told me that it may be related to the length of the parameters that need to be converted. But it didn’t work out even if I tried it.
So if anyone knows the reason, please tell me in the comment section. grateful.

Solution:
Upgrade fastjson to version 1.2.79:
fastjson version 1.2.79

Reprinted to: https://blog.csdn.net/weixin_44504563/article/details/124616391

Guess you like

Origin blog.csdn.net/asd54090/article/details/132391362