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).Warning: It is discouraged to use any of this builder's methods after
build()has been called. Further modifications to this builder might be reflected in any objects that have been built earlier. Later API versions might enforce this suggestion by throwing an exception.- 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 Deprecated Methods Modifier and Type Method Description StructuredDatabuild()JsonSnapshotconfigure(Consumer<com.fasterxml.jackson.databind.ObjectMapper> c)Configure the underlying ObjectMapper by passing in aConsumer.static JsonSnapshotjson()Creates an instance using a defaultObjectMapperwith sensible defaults.static JsonSnapshotjson(com.fasterxml.jackson.databind.ObjectMapper objectMapper)Creates an instance using the explicitly provided ObjectMapper.JsonSnapshotwithComparator(org.skyscreamer.jsonassert.comparator.JSONComparator jsonComparator)Deprecated, for removal: This API element is subject to removal in a future version.Since 1.2.0 - UsewithComparisonRules(Consumer)instead.JsonSnapshotwithCompareMode(CompareMode compareMode)Sets the mode for comparing two json strings.JsonSnapshotwithComparisonRules(Consumer<ComparisonRuleBuilder> rules)Allows to specify extra comparison rules that are applied to certain paths within the json snapshots.static JsonSnapshotwithDefaultObjectMapper()Deprecated, for removal: This API element is subject to removal in a future version.Since 1.4.0 - Usejson()instead.static JsonSnapshotwithObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)Deprecated, for removal: This API element is subject to removal in a future version.Since 1.4.0 - Usejson(ObjectMapper)instead.
-
-
-
Field Detail
-
json
public static final StructuredDataProvider json
Takes Snapshots using jacksonObjectMapperand compare the results usingJSONAssert.
-
-
Method Detail
-
withDefaultObjectMapper
@Deprecated(since="1.4.0", forRemoval=true) @API(status=DEPRECATED, since="1.4.0") public static JsonSnapshot withDefaultObjectMapper()
Deprecated, for removal: This API element is subject to removal in a future version.Since 1.4.0 - Usejson()instead.Creates an instance using a defaultObjectMapperwith sensible defaults. The object mapper can be configured further usingconfigure(Consumer).- Returns:
- A builder for building
StructuredData.
-
json
public static JsonSnapshot json()
Creates an instance using a defaultObjectMapperwith sensible defaults. The object mapper can be configured further usingconfigure(Consumer).- Returns:
- A builder for building
StructuredData.
-
json
public static JsonSnapshot json(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.
-
withObjectMapper
@Deprecated(since="1.4.0", forRemoval=true) @API(status=DEPRECATED, since="1.4.0") public static JsonSnapshot withObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Deprecated, for removal: This API element is subject to removal in a future version.Since 1.4.0 - Usejson(ObjectMapper)instead.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. Can be used to tweak the defaultObjectMapper.The passed Consumer will be called immediately to modify the object mapper in place. That is either the default object mapper or the one that has been passed to
json(ObjectMapper)during construction of this object.- Parameters:
c- The consumer to which the ObjectMapper will be passed.- Returns:
- This instance.
-
withComparator
@Deprecated(forRemoval=true, since="1.2.0") @API(status=DEPRECATED, since="1.2.0") public JsonSnapshot withComparator(org.skyscreamer.jsonassert.comparator.JSONComparator jsonComparator)
Deprecated, for removal: This API element is subject to removal in a future version.Since 1.2.0 - UsewithComparisonRules(Consumer)instead.Sets theJSONComparatorfor comparing actual and expected. If not set, theDefaultComparatoralong withJSONCompareMode.STRICTwill be used.Note: this method can not be used in combination with
withComparisonRules(Consumer)as they will internally overwrite their respective configuration.- 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
-
withCompareMode
@API(status=STABLE, since="1.5.0") public JsonSnapshot withCompareMode(CompareMode compareMode)Sets the mode for comparing two json strings. Defaults toCompareMode.STRICT.- Parameters:
compareMode- The compare mode to use.- Returns:
- This instance.
-
withComparisonRules
@API(status=EXPERIMENTAL, since="1.2.0") public JsonSnapshot withComparisonRules(Consumer<ComparisonRuleBuilder> rules)Allows to specify extra comparison rules that are applied to certain paths within the json snapshots.Note: this method can not be used in combination with
withComparator(JSONComparator)as they will internally overwrite their respective configuration.- Parameters:
rules- A consumer to which aComparisonRuleBuilderwill be passed.- Returns:
- This instance.
-
build
public StructuredData build()
- Specified by:
buildin interfaceStructuredDataProvider
-
-