0

I am trying to hash a JSON object to check for changes. I am using a custom ObjectMapper:

public static final ObjectMapper mapper =
            new ObjectMapper().configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true)
                    .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
                    .configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
                    .configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true)
                    .configure(SerializationFeature.INDENT_OUTPUT, false)
                    .setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
                    .enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)
                    .setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"))
                    .registerModule(new JavaTimeModule());

This seems to work perfectly fine, but obviously doesn't work for arrays inside of the JSON object. My question is how can I go about handling the arrays during the mapping process to make sure they stay in the same order every time?

mortimerfreeze
  • 199
  • 1
  • 1
  • 9
  • 1
    You don’t need to intervene. “An array is an ordered sequence of zero or more values” from https://www.rfc-editor.org/rfc/rfc7159.html. The order is significant so a different order is a changed object. If you want to negate the significance of the order then you need a comparator and sort before serialising. – John Williams Mar 14 '23 at 18:41

0 Answers0