how to use "navtive_type" in flatbuffers? - flatbuffers

here is my test schema:
native_include "mystruct.h"
table testdata
{
data:mystruct (native_type);
}
the flatc shows: error: expecting: table instead got: identifier: native_include.
I can't find any detail informations about how to use native_type in the flatbuffers document.
please, can someone show me some examples how to use, and where should i write "namespace flatbuffers { FlatbufferStruct Pack(const native_type& obj); native_type UnPack(const FlatbufferStruct& obj); }"
thanks a lot!

native_include should be parsed, if it thinks it is an identifier, you may be using an older version of flatc ?
As for native_type, that is an attribute for the struct, not the field, e.g.: struct mystruct (native_type: "mycpptype") { .. } as shown in the documentation here: https://google.github.io/flatbuffers/flatbuffers_guide_use_cpp.html

Related

How to specify XML element names in bpmn-js

If I define a moddle file with bpmn-js like this
{
name: "thisArgument",
superClass: [
"Element"
],
properties: []
},
{
name: "myData",
superClass: [
"Element"
],
properties: [
{
name: "argument",
type: "thisArgument"
}
]
},
Then the resulting XML (when I call saveXML) will have an element called thisArgument, despite the fact that the name is "argument". First, is that a bug? If not, how do I control the output so that the XML contains argument rather than thisArgument? I've searched the docs and examples but can't find how to do this.
The only workaround I found was to make it type: "argument" and then define argument with a superClass of thisArgument and no extra properties (essentially making an alias). However, that only works if all instances of argument are identical. Eg. if the XML needed to be
<A><argument/></A>
<B><argument/></B>
where the argument in A has a different shape than the argument in B, then there would be a conflict since I can't define argument twice.
I can sort of answer my own question. I found this serialize option and experimented, and it mostly does what I want, but sometimes it adds an unwanted xsi:type="originalType" attribute and sometimes it doesn't. Maybe it depends on isBody but I'm not sure. If anyone knows the details of how it works, please reply.
properties: [
{
name: "argument",
type: "thisArgument",
xml: {
serialize: "xsi:type"
},
}
]
The closest thing I found to documentation on it is https://forum.bpmn.io/t/bpmn-json-documentation/1304 which describes it as "additional meta-data impecting XML serialization of a type", so I'd appreciate any extra details anyone can supply.
Update:
The docs don't mention this, but it turns out that serialize: "property" is exactly what I need. This does the same as serialize: "xsi:type" but doesn't add the xsi:type attribute.
xml: {
serialize: "property"
},
I found this by hunting the code in one of the related packages, moddle-xml.
In write.js, there's code that looks for the xsi:type or property entry:
// allow serialization via type
// rather than element name
var asType = serializeAsType(p),
asProperty = serializeAsProperty(p);
In the same file, I found some code that appears to explain why the xsi:type didn't always show up, too:
// only serialize xsi:type if necessary
if (descriptor.name === this.propertyDescriptor.type) {
return attributes;
}

PRISMA: Getting type error on where clause in update method

Have a specific Prisma ORM library error that I need help with.
I have created a migration and pushed it to a postgres db.
I have generated the client model for Prisma and am able to findAll and insert data using the create method.
Where I am having trouble is the update method.
Here's my code
app.post("/articles/:title", async (req: Request, res: Response) => {
const article = await prisma.article.update({
where: { title: req.params.title },
data: { title: req.body.title, content: req.body.content },
})
res.send('The article was posted sucessfully.' + article)
})
I am getting the following error which makes me think that the client is not finding a type 'title' when using the where argument.
app.ts:65:14 - error TS2322: Type '{ title: string; }' is not assignable to type 'ArticleWhereUniqueInput'.
Object literal may only specify known properties, and 'title' does not exist in type 'ArticleWhereUniqueInput'.
65 where: { title: req.params.title },
~~~~~~~~~~~~~~~~~~~~~~~
node_modules/.prisma/client/index.d.ts:784:3
784 where: ArticleWhereUniqueInput
~~~~~
The expected type comes from property 'where' which is declared here on type 'Subset<ArticleUpdateArgs, ArticleUpdateArgs>'
Has anyone else had this issue?
I tried to introspect the database just to make sure the database was captured exactly as is, with title and content fields and then generated the client again.
Many thanks
James
Found the answer: Post answer was a response from Antonie
The fields in
where
needs to be unique.
If you can make some field, let's say date #unique (date: DateTime! #unique), and use that for your where in the upsert, I think it would work (tested on my local).
Use .(find/update/delete)Many() if you are trying to query with multi values.

How to set array property value in code using Carina Test Framework for API tests?

I have the following request json body:
{
...
"attachmentIds": "${attachments}"
...
}
I have a properties file that includes the declaration of the corresponding placeholder
I want to set array of strings in code instead of "attachments" placeholder, but getProperties().setProperty() expects only string value.
How can I achieve it other way or is it possible at all?
Thanks!
As an option you can transform your array into the String in java code. And then pass this String as property value.
Another option, you can pass String array from code and then parse it in your json template.
For example:
String[] arr = { "1", "2", "3" };
apiMethod.addProperty("attachments", arr);
And then in your json:
{
"attachmentIds": [<#list attachments as val>"${val}"<#if val?has_next>,</#if></#list>]
}
Check freemarker documentation to get more details:
https://freemarker.apache.org/docs/ref_builtins_loop_var.html
Also please note that some of freemarker functions (including has_next) are available only in newest versions of library. So make sure to add into your dependencies list. Carina is now in process of migrating to latest freemarker version.

Http4s EntityDecoder not being auto derived for simple case class

I am getting this error:
Cannot decode into a value of type com.blah.rest.model.UserProfile,
because no EntityDecoder[cats.effect.IO, com.blah.rest.model.UserProfile]
instance could be found.
for the following case class:
case class UserProfile(id: Option[Int], firstName: String, lastName: String)
Encountered the error on POST code:
case req # POST -> Root / "v1" / "profiles" =>
req.as[UserProfile] flatMap {(up: UserProfile) =>
Ok(service.createProfile(up).asJson)
}
With the following POST body:
{
"firstName": "Jack",
"lastName": "Appleseed"
}
I think this happens when the body is being converted to UserProfile in req.as[UserProfile]!
But, this is a plain vanilla case class, the EntityDecoder should be auto-derived! I know akka-http does it!
Any ideas/suggestions?
Please Note: Http4sVersion = "0.18.0-M4" and circe version "0.9.0-M1"
The answer is:
req.decodeJson[UserProfile] flatMap {(up: UserProfile) =>
Ok(service.createProfile(up).asJson)
}
The reason you get that is the bridge from a Circe decoder to an http4s EntityDecoder is not implicit. You can make one if you're purely a JSON API, but that's not an assumption the library can generally make.
Adding this dependency:
"io.circe" %% "circe-generic" % "0.9.1"
resolved the auto-encoding of case classes to JSON for me.
It allows for the required import: import io.circe.generic.auto._

JsonIdentityInfo causes objects to be serialized as Ids, and then cant deserialize them

I have a problem with array deserialization when using JsonIdentityInfo. The serialization takes place correctly and the array contains a few Ids where there are cyclic references. However, I cannot figure out how to deserialize the ids into objects. I get an array with some objects and some strings. [I use UUIDs for ids
#JsonIdentityInfo(
generator=ObjectIdGenerators.UUIDGenerator.class,
property="_lineItemExternalId",
scope=LineItemExternal.class
)
The array is serialized as
{
"#class":".WebServiceResponseArrayImpl",
"responseCode":0,
"responseMessage":"OK",
"systemTime":1486803868384,
"data":[
"[Ljava.io.Serializable;",
[
[
"in.cloudnine.nanoerp.model.inventory.LineItemExternal",
{
"lineItemExternalId":"0379de02-d67d-42b1-a764-d2c53f90e474",
"bags":40,
"serialNumber":"1",
"kgs":2000.00,
"manufacturerBatchNumber":"55",
"rate":250.00,
"subtotal":500000.00,
"virgin":true,
"color":{
"_colorId":"4a811a32-2057-4759-b07f-3d70f1a8ec4a",
"company":"abb1f7e2-c42f-43e6-8b44-341fe744d4c2",
"date":"2017-01-22",
"createdOn":"2017-02-09",
"modifiedOn":"2017-02-09",
"systemUser":"f46e9a61-670d-491c-8571-ba7b2e1a55e7",
"colorId":"85f91038-1e6a-4c73-a2f6-4c0e16e48f7f",
"code":"MG",
"name":"Magenta",
"value":null
},
"manufacturer":{
"_manufacturerId":"80a63b5e-33db-4b13-84cc-b9f591ea6b78"
}
}
],
"cee9d79b-77a9-4b3b-a376-ead1d6347d03",
"a15661e1-b4d4-4145-8db8-4e66ad0e4f81"
]
]
}
Here, "cee9d79b-77a9-4b3b-a376-ead1d6347d03", and "a15661e1-b4d4-4145-8db8-4e66ad0e4f81" are LineItemExternal ids, which have been serialized completely in the above json. [Removed for brevity]
The code which throws the error is
Object[]array=createBeanArrayLineItemExternal();
System.out.println("Length of Array:"+array.length);
for(Object obj:array){
LineItemExternal item=(LineItemExternal)obj;
System.out.println(item);
}
}
catch(ClassCastException e){
e.printStackTrace();
}
It throws ClassCastException saying String cannot be cast to LineItemExternal. This means the array contains one object and two strings [the Ids]
Do I need a custom deserializer or is it possible to configure object mapper to do that automatically?
I previously asked the question on disqus and the link to the project src is below.
https://github.com/ks1974in/DeserializationTestForJson.git
The sample input json is in file input.json in the project folder. The test case is in package in.cloudnine.inventory.test;
It is TestSerializationAndDeserialization
The failing test is testWithFile()
Sorry for including so much code. But the previous tests with limited code ALL SUCCEEDED. However, the above test does fail with a class cast exception
Thanks,
Sagar
Please help me.