I need to get Json to my model but i have problems(i am beginner).
my model
https://gist.github.com/anonymous/1c2e88cb83cbeace6f34
and i need to do getting json to my model
and i need json->to model convertion
and i use web service for getting json
and how can i implement object list of jobs to my model
controller
https://gist.github.com/anonymous/c526483b29be0b198bca
i need objects to edit some details and i want to re convert to Json
my opinion is this
i am open new ideas
Thanks...
It looks like you have nearly everything you need there. To convert builds in the JSON to a list of Build, you'd do this:
val js: JsValue = response.json
(js \ "builds").as[List[Build]]
To modify a field, you can do, for example:
val build = builds.head // get the first build
val modifiedBuild = build.copy(name = "new name")
Then to convert that back to being JSON:
Json.toJson(mp)
Related
I am trying to use AWS SDK GO v2: https://github.com/aws/aws-sdk-go-v2
And seem to have a hard time unmarshalling the dynamodb.GetItemOutput's Item attribute which is of type map[string]types.AttributeValue.
in AWS SDK GO v1, it's easy to call dynamodbattribute.UnmarshalMap(result.Item, &data) to unmarshal the result. But on v2, I can't find any way to do this.
does anyone have an idea how to do it ?
I was able to find an answer, thanks to Sean McGrail, one of the contributors of the aws-sdk-go-v2 project.
The attributevalue library has methods to unmarshal and marshal the query results to your specific business model/struct:
https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue
I just needed to manually import this library since this wasn't pre-included during download of aws-sdk-go-v2:
go get github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue
Using github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue
You can unmarshal each result item returned by the "Scan" API into a go struct.
var object struct {
PropertyA string `json:"property_a"`
PropertyB string `json:"property_b"`
}
_ = attributevalue.UnmarshalMap(<item>, &object)
Whenever I have to unmarshall JSON data, which is the default output of most AWS SDK responses, I:
Barf out the entire JSON blob (fmt.Println(result))
Copy and paste that into https://mholt.github.io/json-to-go
Snarf the resulting struct into my code, say as MyStruct
Call json.Unmarshal([]byte(result), &MyStruct)
When there is a need to store protobuf3 message coming in form of Java instance (from the generated java class), the best option is to store the object itself and later to read it back from the database.
My usecase it to store such messages in Mongodb.
While investigating this, I couldn't find a way, so decided to ask here.
You could transform the Protobufs Java class to JSON and from JSON to an org.bson.Document and then write the document and reverse that transform when reading.
See JsonFormat for more details.
Here's a simple example on the write side:
YourProtobufsClass anInstance = YourProtobufsClass.getDefaultInstance();
String json = JsonFormat.printer().print(yourProtobufsClass);
Document document = Document.parse(json);
mongoClient.getDatabase(...).getCollection(...).insertOne(document);
Here's a simple example on the read side:
JsonFormat.Parser parser = JsonFormat.parser();
FindIterable<Document> documents = collection.find(...);
for (Document document : documents) {
YourProtobufsClass.Builder builder = YourProtobufsClass.newBuilder();
parser.merge(document.toJson(), builder);
// now you can build an instance of your protobufs class which
// has been populated from the retrieved JSON
YourProtobufsClass anInstance = builder.build();
}
Noob to Gatling/Scala here.
This might be a bit of a silly question but I haven't been able to find an example of what I am trying to do.
I want to pass in things such as the baseURL, username and passwords for some of my calls. This would change from env to env, so I want to be able to change these values between the envs but still have the same tests in each.
I know we can feed in values but it appears that more for iterating over datasets and not so much for passing in the config values like I have.
Ideally I would like to house this information in a JSON file and not pass it in on the command line, but maybe thats not doable?
Any guidance on this would be awesome.
I have a similar setup and you can use pure scala here .In this scenario you can create an object called Config for eg
object Configuration { var INPUT_PROFILE_FILE_NAME = ""; }
This class can also read a file , I have the below code in the above object
val file = getClass.getResource("data/config.properties").getFile()
val prop = new Properties()
prop.load(new FileInputStream(file));
INPUT_PROFILE_FILE_NAME = prop.getProperty("inputProfileFileName")
Now you can import this object in Gattling Simulation File
val profileName= Configuration.INPUT_PROFILE_FILE_NAME ;
https://docs.scala-lang.org/tutorials/tour/singleton-objects.html.html
Iam currently having a json object say student.json. The Structure looks something like this
{"serialNo":"1","name":"Rahul"}
{"serialNo":"2","name":"Rakshith"}
case class Student(serialNo:Int,name:String)
student.json is a huge file which Iam planning to parse through a spark job. And the snippet :
import play.api.libs.json.{ Json, JsObject, JsString }
.....
.....
for(jsonLine <-sc.textFile("student.json")
student<- Json.parse(jsonLine).asOpt[Student])
yield(student.serialNumber -> student.name)
Is there a better way to do this??
If student.json is a huge file, and each line is just a valid json object, you should do:
val myRdd = sc.textFile("student.json").map(l=> Json.parse(l).asOpt[Student])
If you want to get the RDD to your local master, you can:
val students = myRdd.collect()..// then you can do operate it in the old fashion way.
I saw you are importing play.api.libs.json which is from the Play Framework. I don't think running a Spark program in a web application is a good idea...
I am a Scala/PlayFramework noob here, so please be easy on me :).
I am trying to create an action (serving a GET request) so that when I enter the url in the browser, the browser should download the file. So far I have this:
def sepaCreditXml() = Action {
val data: SepaCreditTransfer = invoiceService.sepaCredit()
val content: HtmlFormat.Appendable = views.html.sepacredittransfer(data)
Ok(content)
}
What it does is basically show the XML in the browser (whereas I actually want it to download the file). Also, I have two problems with it:
I am not sure if using Play's templating "views.html..." is the best idea to create an XML template. Is it good/simple enough or should I use a different solution for this?
I have found Ok.sendFile in the Play's documentation. But it needs a java.io.File. I don't know how to create a File from HtmlFormat.Appendable. I would prefer to create a file in-memory, i.e. no new File("/tmp/temporary.xml").
EDIT: Here SepaCreditTransfer is a case class holding some data. Nothing special.
I think it's quite normal for browsers to visualize XML instead of downloading it. Have you tried to use the application/force-download content type header, like this?
def sepaCreditXml() = Action {
val data: SepaCreditTransfer = invoiceService.sepaCredit()
val content: HtmlFormat.Appendable = views.html.sepacredittransfer(data)
Ok(content).withHeaders("Content-Type" -> "application/force-download")
}