type string is not assignable to type MenuItems[] - angular9

i am storing json data to session but while retrieving it shows below error
error : type string is not assignable to type MenuItems[]
this.datasource.data=sessionStorage.getItem('MenuData')

Only store string in sessionStorage, by using JSON.stringfy() and while retrieving use JSON.parse() method

Related

How to type Date types with Prisma and JSON blobs?

There seems to be an issue with prisma's serialization of JSON blobs wrt Date types.
I wonder if anyone else has seen this and has some guidance/workaround.
This is for a JSON field with Planetscale which is basically MySQL driver.
I have an object with a Date field, that I want to encode. This is a blob of data coming back from an external API
eg my object tp has a field defined typed a Date:
trained_at: Date;
in my prisma schema for tunePrompt I have a JSON field:
model TunePrompt {
apiData Json? // from external API
But when I try to write to that apiData JSON field:
const data = {
apiData: tp,
}
const newPrompt = await prisma.tunePrompt.create({ data })
Property 'trained_at' is incompatible with index signature.
Type 'Date' is not assignable to type 'InputJsonValue | null | undefined'.",
if I were to do JSON.stringify(tp) this works without error, but then I get double escaped JSON.
The generated types are something like:
export type TunePromptCreateInput = {
apiData?: NullableJsonNullValueInput | InputJsonValue
}
the only workaround i've found is to type the Date fields as a string, but I'm sure this is going to lead to other parsing problems later.
Maybe I can look into typing the JSON blob, but I don't think that would solve the issue as its the serialization I think that's the problem.

Error on Parsing the empty string for an Enum : JSON parse error: Cannot coerce empty String (\"\")

I've been trying to solve this error which happens upon parsing an empty string for my enum values.I have tried the following solutions
getJacksonObjectMapper(template).coercionConfigFor(LogicalType.Enum).setCoercion(CoercionInputShape.EmptyString,CoercionAction.AsNull)
and
getJacksonObjectMapper(template).deserializationConfig.with(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)
getJacksonObjectMapper(template).enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)
can someone help me out with this problem ? The error trace looks like this
JSON parse error: Cannot coerce empty String (\"\") to `Gender` value (but could if coercion was enabled using `CoercionConfig`); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot coerce empty String (\"\") to `Gender` value (but could if coercion was enabled using `CoercionConfig`)\n at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream);
and my enum is
enum Gender{
M, F;
}
.enable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)

Can we check if object is a key-value type in Kotlin

I want to check if a object is a key-value type. Is there anywhere to check it?
Do you means ket-value is map collection? Right?
You can check type using 'is'.
if (tmp is String)
print("this type is string")

Elasticsearch 8.0.0 mapper_parsing_exception of a string literal for field type "flattened"

I have a Problem to insert a document via Api to my ES 8.0.0.
In my IndexTemplate I defined a mapping of a property called [Data] of type "flattend".
For "normal" JSON-Objects it works fine. But when I try to insert a plain string literal (for example "test") or a number (for example 4) I get a "400 Bad Request". JSONLint says it's a valid JSON!!
{
....
"Data": "test",
....
}
Can i configure ES to accept such kind of JSON for type "flattened"??
As Elasticsearch document mentions:
The flattened type provides an alternative approach, where the entire
object is mapped as a single field. Given an object, the flattened
mapping will parse out its leaf values and index them into one field
as keywords.
So, the value provided for the "flattened" field type should be a JsonObject.
Hence, below works as where "full_name" is of type "flattened"
"full_name":{
"name":"nishikant"
}
But below does not
"full_name":"nishikant".
Same has been given in exception
"reason" : "Failed to parse object: expecting token of type [START_OBJECT] but found [VALUE_STRING]"

JSON decode function output type with lint package

I am following the offical documentation here: https://flutter.dev/docs/development/data-and-backend/json#serializing-json-inline
Map<String, dynamic> user = jsonDecode(jsonString);
print('Howdy, ${user['name']}!');
print('We sent the verification link to ${user['email']}.');
When using the lint package from pub.dev I get the error:
A value of type 'dynamic' can't be assigned to a variable of type 'Map<String, dynamic>'.
Try changing the type of the variable, or casting the right-hand type to 'Map<String, dynamic>'.dartinvalid_assignment)
I see the problem that the JSON fields have to be of dynamic type, however, what is the best way to deal with the lint package in this case? Also, the extraction of the decoded fields (i.e. userName = user['name']) throws an error because of type mismatch (dynamic vs String for example).