简体   繁体   中英

Rest Assured - send a pojo in an array

I have a Pojo that creates a json object with values This creates an object fine eg

public class Collections {

private String reference;
private String collectionDate;

public String getReference() {
    return reference;
}

public void setReference(String reference) {
    this.reference = reference;
}

public String getCollectionDate() {
    return collectionDate;
}

public void setCollectionDate(String collectionDate) {
    this.collectionDate = collectionDate;
}}

This creates a json object just fine

{reference:"test",collectionDate:"test"}

But my api only accepts objects encapsulated as an array eg

[{reference:"test",collectionDate:"test"}]

I then want to pass this object in an array into the Body of me restAssured POST request

can anyone help me please?

Thanks!

Here's a couple options...

List<Collection> collections = new ArrayList<>();
collections.add(new Collection("foo", "bar"));

or...

List<Collection> collections = List.of(new Collection("foo", "bar"));

Note, i've assumed your pojo would be called 'Collection' rather than 'Collections'

Whatever you're using to convert it into Json should also parse the above into the form you're expecting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM