Comments (11)
Hi, thanks for feedback. To be honest, capturing values does not seem to fit to the library. There are several possible solutions.
- Use json-path to access the values
- Use Hamcrest matchers. You can already use Hamcrest matchers with JsonUnit like this
assertThatJson("{\"test\":\"one\"}").node("test").matches(equalTo("one"));
You can use custom capturing matcher (similar to Mockito ArgumentCaptor)
from jsonunit.
from jsonunit.
Sure, PRs are always nice.
It reminds me this feature recently added to JsonUnit a2c26ab#diff-6c9cdaf0685d47feb195c5cd7da1eb5aR1021 isn't it what you need?
from jsonunit.
from jsonunit.
OK, I see what you mean. You need additional param. Something like
assertJsonEquals("{\"test\": \"${json-unit.matches:mymagic}[param]\"}", "{\"test\":1}", JsonAssert.withMatcher("mymagic", myMagicInstance));
That can be done.
from jsonunit.
No need for PR, I think I know what to do. If you do not mind, I will base it on matchers, will just add a parameter.
from jsonunit.
What about this? c85a70f#diff-6c9cdaf0685d47feb195c5cd7da1eb5aR1030
from jsonunit.
from jsonunit.
Released as 1.24.0
from jsonunit.
from jsonunit.
Finally got around to actually using this for real, worked perfectly. I can now compare both XML documents using XML unit, and JSON documents using JsonUnit and, as a side effect of the comparison, capture values into user defined variables using a similar ${} extension mechanism. Brilliant.
from jsonunit.
Related Issues (20)
- ObjectMapper customization by autowiring from Spring HOT 4
- Option.IGNORING_CASE HOT 1
- Vulnerable dependency in net.javacrumbs.json-unit:json-unit-assertj:2.35.0
- Provide a way back to `JsonAssert` from `JsonMapAssert` HOT 4
- Document Hamcrest assertions if root is array HOT 1
- Numerical comparison regression in 2.36.0 HOT 4
- Ease assertions on content of JSON files HOT 1
- Picking gson instance HOT 3
- Diff message is lost when using jsonEquals with rest-assured HOT 2
- Test Fails Without Manually Adding Logging Dependency HOT 2
- withTolerance() but only for doubles and floats HOT 7
- floating point numbers comparison regression HOT 5
- json-unit.any-* for array elements
- How to validate a java.time.Duration? HOT 7
- when abs(a-b) = tolerance,test did not fail HOT 3
- Make it possible to use `withMatcher` for `WebTestClientJsonMatcher` HOT 2
- Release notes for 3.2.0 missing HOT 3
- JDK 11 compatibility HOT 2
- Print the compared data in the report HOT 6
- Mark JSON-containing paramaters with @Language("JSON") HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonunit.