Java Spring:(LinkedHash)Map中的枚举键未排序

My entity Mealplan has an mealsPerWeek property as a LinkedHashMap.

@Entity
public class Mealplan {

@Id
private int id;

@ManyToMany
private Map<Weekday, Meal> mealsPerWeek = new LinkedHashMap<>();

public Map<Weekday, Meal> getMealsPerWeek() {
    return mealsPerWeek;
}

}

The key of the map property is Weekdayand is an enumeration:

public enum Wochentag {
    Monday, Tuesday, Wednesday, Thursday, Friday
}

现在,我希望在我的API中以正确的枚举顺序显示餐食。但是它显示的非常随机:

{
id: 1,
mealsPerWeek: {
  Tuesday: {
   id: 3,
   name: "Salad",
   preis: 3,
   art: "vegan"
},
  Monday: {
   id: 4,
   name: "Linsensuppe",
   preis: 23.5,
   art: "vegan"
},

如何在我的REST API中对其进行排序,以便它以正确的顺序显示密钥?

评论