Gson changes the order of PriorityQueue in java when using new Gson().toJson(priorityQueue)
- Dominant language
- Java
- Stars
- 24.2k
- Forks
- 4.5k
- Avg merge
- 6d 4h
- Merged PRs (30d)
- 12
Description
# Gson version 2.9.1
# Java / Android version
Java 17
IntelliJ IDEA 2023.1 (Ultimate Edition)
Build #IU-231.8109.175, built on March 28, 2023
Runtime version: 17.0.6+10-b829.5 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 13.0.1
GC: G1 Young Generation, G1 Old Generation
Memory: 4096M
Cores: 8
# Used tools
- [ ] Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
- [ ] Gradle 8.0
# Description
When i am printing a PriorityQueue using new Gson().toJson(priorityQueue) i get the order of the integers not in the correct way
## Expected behavior
PrintingFromWhileLoop: 1
PrintingFromWhileLoop: 2
PrintingFromWhileLoop: 3
PrintingFromWhileLoop: 4
PrintingFromWhileLoop: 5
PrintingFromWhileLoop: 9
## Actual behavior
MyPriorityQueueWithoutPrettyPrint: [1,2,5,4,3,9]
# Reproduction steps
Queue mQueue = new PriorityQueue<>();
mQueue.offer(4);
mQueue.offer(2);
mQueue.offer(9);
mQueue.offer(1);
mQueue.offer(3);
mQueue.offer(5);
https://github.com/wincelee/MyLeetCodes/blob/c8c5e569dc8fec99070f68c568cc786833faaa6e/src/main/java/leet_code_quizes/easy/GsonPriorityQueueBug.java
Contributor guide
Assessment
This issue has not been assessed yet.