Class JsonSnapshot

  • All Implemented Interfaces:
    StructuredDataProvider

    @API(status=STABLE)
    public final class JsonSnapshot
    extends Object
    implements StructuredDataProvider
    Serializes snapshots as json using jackson. Use either the static factory methods or the ready-to-use static instance json. You can either provide an explicit ObjectMapper or use one with sensible defaults.

    Either way, the ObjectMapper can be further configured by calling configure(Consumer).

    Author:
    Simon Taddiken
    • Field Detail

      • json

        public static final StructuredDataProvider json
        Takes Snapshots using jackson ObjectMapper and compare the results using JSONAssert.
    • Method Detail

      • withDefaultObjectMapper

        public static JsonSnapshot withDefaultObjectMapper()
        Creates an instance using a default ObjectMapper with sensible defaults. The object mapper can be configured further using configure(Consumer).
        Returns:
        A builder for building StructuredData.
      • withObjectMapper

        public static JsonSnapshot withObjectMapper​(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
        Creates an instance using the explicitly provided ObjectMapper.
        Parameters:
        objectMapper - The ObjectMapper to use for taking snapshots.
        Returns:
        A builder for building StructuredData.
      • configure

        public JsonSnapshot configure​(Consumer<com.fasterxml.jackson.databind.ObjectMapper> c)
        Configure the underlying ObjectMapper by passing in a Consumer.
        Parameters:
        c - The consumer to which the ObjectMapper will be passed.
        Returns:
        This instance.
      • withComparator

        @API(status=EXPERIMENTAL)
        public JsonSnapshot withComparator​(org.skyscreamer.jsonassert.comparator.JSONComparator jsonComparator)
        Sets the JSONComparator for comparing actual and expected. If not set, the DefaultComparator along with JSONCompareMode.STRICT will be used.
        Parameters:
        jsonComparator - The comparator to use.
        Returns:
        This instance.
        API Note:
        This method is likely going to be replaced with a wrapper API around JSONAssert types. The JSONAssert API is a bit awkward to use and I'd like to remove it as a visible dependency altogether