Class JsonSnapshot
- java.lang.Object
-
- de.skuzzle.test.snapshots.data.json.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 instancejson. You can either provide an explicitObjectMapperor use one with sensible defaults.Either way, the ObjectMapper can be further configured by calling
configure(Consumer).- Author:
- Simon Taddiken
-
-
Field Summary
Fields Modifier and Type Field Description static StructuredDataProviderjsonTakes Snapshots using jacksonObjectMapperand compare the results usingJSONAssert.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StructuredDatabuild()JsonSnapshotconfigure(Consumer<com.fasterxml.jackson.databind.ObjectMapper> c)Configure the underlying ObjectMapper by passing in aConsumer.JsonSnapshotwithComparator(org.skyscreamer.jsonassert.comparator.JSONComparator jsonComparator)Sets theJSONComparatorfor comparing actual and expected.static JsonSnapshotwithDefaultObjectMapper()Creates an instance using a defaultObjectMapperwith sensible defaults.static JsonSnapshotwithObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)Creates an instance using the explicitly provided ObjectMapper.
-
-
-
Field Detail
-
json
public static final StructuredDataProvider json
Takes Snapshots using jacksonObjectMapperand compare the results usingJSONAssert.
-
-
Method Detail
-
withDefaultObjectMapper
public static JsonSnapshot withDefaultObjectMapper()
Creates an instance using a defaultObjectMapperwith sensible defaults. The object mapper can be configured further usingconfigure(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 aConsumer.- 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 theJSONComparatorfor comparing actual and expected. If not set, theDefaultComparatoralong withJSONCompareMode.STRICTwill 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
-
build
public StructuredData build()
- Specified by:
buildin interfaceStructuredDataProvider
-
-