I have a camunda bpmn workflow where the start-events required some variables.
One of the needed variable is of type 'date':
{
"variables": {
"stichtagFrist": {
"value": "2021-09-08T00:00:00",
"type": "date"
}
}
}
now trying to add a new Instance having the above mentioned json, I get the following exception:
Cannot instantiate process definition d1f43d8e-211f-11ec-8fdf-0242ac110002: Cannot convert value '2021-09-08T00:00:00' of type 'date' to java type java.util.Date"
How do I need to POST the json that Camunda can interpret it as "date" so that I can use this variable e.g. in timer-events etc.?
Are there any rules for booleans too?
https://github.com/camunda/camunda-bpm-platform/blob/7c5bf37307d3eeac3aee5724b6e4669a9992eaba/engine-rest/engine-rest/src/main/java/org/camunda/bpm/engine/rest/dto/VariableValueDto.java#L109
Uses a Jackson ObjectMapper to parse the value. It requires this format:
{
"variables": {
"stichtagFrist": {
"value": "2021-09-08T00:00:00.0+0000",
"type": "date"
}
}
}
From the documentation:
In the REST API, the type names start with a capital letter, i.e., String instead of string.
Try "Date" instead of "date", that should do the trick.
Related
I am using .Net 6 WebAPI. I need to accept a generic JSON array as input. The properties present in each JSON document is not known before. So I cannot Deserialize to specific object type. So I am looking for 2 inputs.
a) What should be input datatype to accept this in body, when using System.Text.Json? Previously, we have used JArray using JSON.NET.
b) How can I then read this input as an array so that I can then convert into generic JsonObject type?
[
{ "prop1" : "value1", "prop2" : "value1"},
{ "prop3" : "value3", "prop4" : "value4"},
{ "propx" : "valuex", "propy" : "value6", "nested": { "other": [1,23,45] }}
]
I am also open to option of accepting NDJSON.
Thanks!
If all I do is create a new .net Web API from the standard template and add the following action:
[HttpPost]
public async Task<IActionResult> Post(JsonArray array)
{
foreach(var node in array)
{
Console.WriteLine(node);
}
return Ok();
}
And pass the content you have specified in the question using the built-in swagger UI:
And I can step through in the debugger and observe that the request has been deserialized to do what I please with:
From body you can receive ([FromBody]List<object> input) or ([FromBody]List<dynamic> input) and access to properties dynamically or serialize to typed objects.
I have an existing JSON data feed between multiple systems which I do not control and cannot change. I have been tasked with writing a schema for this feed. The existing JSON looks in part like this:
"ids": [
{ "type": "payroll", "value": "011808237" },
{ "type": "geid", "value": "31826" }
]
When I try to define a JSON schema for this, I wind up with a scrap of schema that looks like this:
"properties": {
"type": { <====================== PROBLEM!!!!
"type": "string",
"enum": [ "payroll", "geid" ]
},
"value": {
"type": [ "string", "null" ],
"pattern": "^[0-9]*$"
}
}
As you might guess, when the JSON validator hits that "type" on the line marked "PROBLEM!!!" it gets upset and throws an error about how type needs to be a string or array.
That's a bug in the particular implementation you're using, and should be reported as such. It should be able to handle properties-that-look-like-keywords just fine. In fact, the metaschema (the schema to valid schemas) uses "type" in exactly this way, along with all the other keywords too: e.g. http://json-schema.org/draft-07/schema
I wonder if it is not making use of the official test suite (https://github.com/json-schema-org/JSON-Schema-Test-Suite)?
You didn't indicate what implementation you're using, or what language, but perhaps you can find an alternative one here: https://json-schema.org/implementations.html#validators
I found at least a work-around if not a proper solution. Instead of "type" inside "properties", use "^type$" inside "patternProperties". I.e.
"patternProperties": {
"^type$": {
"type": "string"
}
}
Unfortunately there doesn't seem to be a great way to make "^type$" a required property. I've settled for listing all the other properties as "required" and setting the min and max property counts to the number that should be there.
iam getting below response from api.
{
"error": {
"serverTime": 1564066755618,
"id": "VALIDATION_EXCEPTION",
"category": "system",
"message": "errors: [property: username; value: ; constraint: EMAIL_INLINE_ERROR_MESSAGE_1; property: username; value: ; constraint: EMAIL_INLINE_ERROR_MESSAGE_1; property: username; value: ; constraint: EMAIL_INLINE_ERROR_MESSAGE_1"
}
}
and iam checking the assertion using below way.
{"error":
{"serverTime":"#notnull",
"id":"VALIDATION_EXCEPTION",
"category":"system",
"message":"#notnull"
}
}
now I want to write a assertion for the above respose, like I want to check for field message contains the words "EMAIL_INLINE_ERROR_MESSAGE_1" and how many time it came.
Use Java interop. Then you can figure out the solution on your own. Normally no one needs this kind of validation, so it is not built in.
Please read the documentation: https://github.com/intuit/karate#calling-java
I have a property in my JSON schema like this:
"properties": {
"theme": {
"type": "boolean",
"title": "Theme",
"enum": ["Light", "Dark"]
}
}
This property is stored in my database table as a boolean, with 1 for light, 0 for dark. The problem is that when I fill out the form generated by the schema it errors, telling me that the value of root.theme must be one of [true, false] and won't proceed to my backend handler.
There is a solution I found that I'm currently utilising, which is changing the "type" to string, and handling it on the backend side, by converting the string value I receive into the boolean corresponding to it.
I am wondering whether JSON schema natively supports custom naming for true & false in a boolean property.
This is not possible as of draft-7 (current at time of writing)
I am looking for a library or framework that does JSON to Objective-C relational object mapping.
i.e. I need to map JSON containing objects, array of objects and dictionaries of objects to my custom objects.
something like:
DataObject {
"user" : {
"name":"Peter",
"id":1234
}
"place": "UK"
"job": {
"title" : "CTO",
"salary" : 1234567
}
"employess": [
{
"name":"Carlton",
"id":1235
},
{
"name":"Hugo",
"id":12346
}]
}
So there is a DataObject a UserObject and an employees array consisting of UserObjects.
I would like for the mapping from the JSON to my DataObject to happen "automatically", of course meant as I would like to describe the objects and there relations in the Object class and have the mapping done from this, instead of manually mapping each nested object.
(First level native objective-c properties are easily done with setValue:forKey and other KVO methods, but from there on it gets complicated).
I have been testing out RestKit but it seems there is no way to pick and choose which functionality you need from that framework, it is either all of it or none of it, and I do find it does too much for my needs.
Are anyone familiar with a library etc. out there that can do this?
Thank you in advance.
To map JSON to Objective-C objects, I have tried RestKit. I used it a while ago, so my criticisms might not apply anymore.
What I found out: nice idea. Not too complicated to plug-in. If it works, great for you. But if not, or if you need to push it a bit further, good luck to debug.
I regret the time I invested in it.
I am only looking for JSON to Objective-C objects, not the other way around.
I found a link on SO to JTObjectMapping - but can't find the original answer. Seems more lightweight and close to what I was searching, but I did not had the opportunity to try it.
An other similar class: jastor.
I prefer the approach of this two classes over RestKit, as it only takes care of one job, whereas RestKit tried to handle everything.
What you have posted above isn't valid JSON. If you made it valid JSON what you want to do is impossible without a specific schema, eg.
{
"DataObject": {
"user": {
"name": "Peter",
"id": 1234
},
"place": "UK",
"job": {
"title": "CTO",
"salary": 1234567
}
}
}
Is Dataobject a dictionary or an Object? What about User or Job? What is User is an instance of NSUser and job is an NSDictionary?
On the other hand, if you have a known schema:-
[
{
"class": "DataObject",
"properties": {
"user": {
"class": "User",
"properties": {
"name": "Peter",
"id": 1234
}
},
"place": "UK",
"job": {
"title": "CTO",
"salary": 1234567
}
}
}
]
you don't need a framework as it is trivial to map to your objects yourself once you have valid JSON. Pseudocode:-
createWithDict(dict) {
var newOb = create new(dict["class"]);
dict.properties.each( val, key ) {
if(val is dictionary && val.hasproperty("class"))
val = createWithDict(val)
newOb[key] = val
}
return newOb;
}