Question: / / fill out the code and make sure it works / / dto . java package question 2 ; public class Dto { public

//fill out the code and make sure it works
//dto.java
package question2;
public class Dto {
public static Dto getSampleDto(){
return null;
}
}
//question2.java
package question2;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.testng.Assert;
import org.testng.annotations.Test;
public class Question2{
/**
* You are creating an api that returns some data about characters for a video game
* The devs on another team have provided you a sample json payload with the data they would like to receive
* Create DTO objects that will serialize to the following sample payload
*/
@Test
public void test(){
String sampleJson ="""
{
"name": "Dragon config",
"datapoints": [
{
"name": "Dragon",
"favoriteNumber": 100,
"color": "Grey",
"data": {
"a": 1,
"b": 2,
"c": "C",
"dataMapping": {
"green": {
"name": "Wings",
"count": 2
}
}
}
}
]
}""";
Gson gson = new GsonBuilder().setPrettyPrinting().create();
var dto = Dto.getSampleDto();
Assert.assertEquals(gson.toJson(dto), sampleJson);
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!