I want to make a structure like given below.
{
"key1": {
"key2": "uuid" //uuid here
}
}
how to make this on serverless.yml file with indentation.
Related
I'm trying to know how I can use a {"result": {}} json with diferents types, I don't have any idea how to construct the class or reused a class Result.
Think of it as having a Map<String, dynamic> before parsing it as encoding/decoding it as JSON. This would allow you to have the following structure:
{
"result": {
"int": 2,
"String": "Sting vaue",
"bool": true
}
}
#Field(index = FieldIndex.analyzed, type = FieldType.String)
How to add annotation here to disable norms for the analysed field
As there is no way to add norms enable-false attribute as part of #field annotations in java entity, we can add all mappings (all required types with attributes as mappings) in mappings.json file and refer this file in entity file. Like as below
#Document(indexName = "jobindex")
#Setting(settingPath = "/config/elasticsearch-settings.json")
#Mapping(mappingPath = "/config/mappings.json") //THIS ONE TO ADD
public class JobIndex implements Serializable {
}
and mappings.json look like
"mappings": {
"_doc": {
"properties": {
"title": {
"type": "text",
"norms": { "enabled": false }
}
}
}
}
NOTE: when you add specific attributes as part of mappings.json which are not available in java #Field annotations then better add all field annotations part of json file rather than in java#Field annotations. So the conclusion is java entity should be without field annotations and all mappings should be in mappings.json file and that file should be referred in entity header as mentioned in the first code block of this answer.
Is it possible to define properties in a Swagger/OpenAPI definition that can be one of two types.
For example, our API allows a source ID to be sent as a string, or a source object. The source object has a fixed schema:
Source ID:
{
"source": "src_123"
}
Source Object:
{
"source": {
"foo": "bar"
}
}
I am unsure how to represent this in my Swagger definition.
I tried the following code in Avro IDL which references the logical type timestamp-millis and it doesn't work.
Is there an import required to use logical types in Avro IDL? Or are logical types not useable, and I need to use the primitive type (long in this case) instead?
protocol test {
record test {
timestamp-millis time;
}
}
Results in:
Exception in thread "main" org.apache.avro.compiler.idl.ParseException: Undefined name 'timestamp', at line 3, column 9
This works of course:
protocol test {
record test {
long time;
}
}
You can use a generic annotation:
protocol test {
record test {
#logicalType("timestamp-millis")
long time;
}
}
There's actually also a shorthand you can use for timestamp-millis and a handful of other logical types (the documentation hasn't been released yet, see here for the full list of aliases):
protocol test {
record test {
timestamp_ms time;
}
}
LogicalType timestamp-millis is used with type long, so you may use schema like this:
{
"type" : "record",
"name" : "Test",
"fields" : [ {
"name" : "time",
"type" : {
"type" : "long",
"logicalType" : "timestamp-millis"
}
}]
}
var myObjectList = (List<MyObject>)JsonConvert.DeserializeObject(strResponseMessage, typeof(List<MyObject>));
the above works to deserialise a JSON string to a list of custom objects when the JSON has the following format
[
{
"Name": "Value"
},
{
"Name": "Value"
},
{
"Name": "Value"
},
"Name": "Value"
}
]
I don't know how to do the same when the format is like this
{
"ReturnedData" : [
{
"Name": "Value"
},
{
"Name": "Value"
},
{
"Name": "Value"
},
"Name": "Value"
}
]
}
I can get the data like this
JObject information = JObject.Parse(strResponseMessage);
foreach (dynamic data in information)
{
//convert to object here
}
and that works for Android but it seems that you cannot use a type of 'dynamic' for iOS as I get the error:
Object type Microsoft.CSharp.RuntimeBinder.CSharpInvokeMemberBinder cannot be converted to target type: System.Object[]
What step am I missing to convert the second JSON string to the first?
If JsonConvert is JSON.Net just instead of List use
public class MyClass {
public List<MyObject> ReturnedData { get; set; }
}
You can't use the dynamic keyword on iOS as its forbidden to generate code as it states in this link.
Quote:-
No Dynamic Code Generation
Since the iPhone's kernel prevents an application from generating code dynamically Mono on the iPhone does not support any form of dynamic code generation.
These include:
The System.Reflection.Emit is not available.
Quote:-
System.Reflection.Emit
The lack of System.Reflection. Emit means that no code that depends on runtime code generation will work. This includes things like:
The Dynamic Language Runtime.
Any languages built on top of the Dynamic Language Runtime.
Apparently there is some support creeping in from v7.2 as can be seen in this link - See #Rodja answer. - however - its very experimental and has flaws preventing this from fully working.
Your best approach would be to process the JObject - without - reying on the dynamic keyword and you will be alright on both Android and iOS.
Thanks for your replies - I was able to solve it as follows
JObject information = JObject.Parse(strResponseMessage);
string json = JsonConvert.SerializeObject(strResponseMessage["ReturnedData "]);
var myObjectList = (List<MyObject>)JsonConvert.DeserializeObject(json , typeof(List<MyObject>));
Works perfectly!