Ordering { @Override public boolean equals(Object obj) { if (!(obj instanceof Ordering)) { return false; } Ordering o = (Ordering) obj; return Objects.equals(queryName, o.queryName) && Objects.equals(order, o.order); } Ordering(String fieldName, SortOrder order);  Ordering(String fieldName, String queryName, SortOrder order); @JsonCreator static Ordering fromString(String ordering); @JsonValue String jsonValue(); String getQueryName(); String getFieldName(); SortOrder getOrder(); void setOrder(SortOrder order); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test public void testJsonWithField() throws Exception { Ordering o1 = new Ordering("foo", SortOrder.ASC); String json = mapper.writeValueAsString(o1); Ordering o2 = mapper.readValue(json, Ordering.class); assertThat(o2).isEqualToComparingFieldByField(o1); assertThat(o2.equals(o1)).isTrue(); o1 = new Ordering("foo", SortOrder.DESC); json = mapper.writeValueAsString(o1); o2 = mapper.readValue(json, Ordering.class); assertThat(o2).isEqualToComparingFieldByField(o1); }
@Test public void testJsonWithQueryField() throws Exception { Ordering o1 = new Ordering("foo", "bar", SortOrder.ASC); String json = mapper.writeValueAsString(o1); Ordering o2 = mapper.readValue(json, Ordering.class); assertThat(o2).isEqualToComparingFieldByField(o1); assertThat(o2.equals(o1)).isTrue(); o1 = new Ordering("foo", "bar", SortOrder.DESC); json = mapper.writeValueAsString(o1); o2 = mapper.readValue(json, Ordering.class); assertThat(o2).isEqualToComparingFieldByField(o1); }