Jackson parsing fails for json string with encoded value - jackson

I have a encrypted string, if I try to use ObjectMapper readTree, then I get Json parse exception.. Any idea how I can let json parser know this to consider the value as string..
{"a" :"encryptedStr"}
Sample code:
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(messageBody);

Related

Deserialize JsonArray with kotlinx serialization

I have the following Json object:
{
"List":[
"string1",
"string2",
"string3",
"..."
]
}
This deserializes into a JsonArray containing JsonLiterals.
When deserializing this and trying to iterate over it I get an error:
java.lang.ClassCastException: kotlinx.serialization.json.JsonLiteral cannot be cast to java.lang.String
What would be the standard way to achieve something like that?
First, make sure that you are using the latest version of kotlinx.serialization.
A comment in the implementation of JsonLiteral states that
JsonLiteral is deprecated for public use and no longer available. Please use JsonPrimitive instead
JsonPrimitive has the isString method to check if it is a string and you can then access it using its content method.

No converter found capable of converting from type Map<String, Object> to org.neo4j.driver.Value

I'm trying to update properties in a Node by passing HashMap<String, Object> as node properties in custom query using #Query in spring-data-neo4j
query reference from neo4j documentation
#Query("MATCH (m:Person {nid: $from})\n" +
"SET m += $props" +
"RETURN m")
Person updateInfo(#Param("from") String id, #Param("props") Map<String, Object> properties);
where it throws error on type conversion as below:
No converter found capable of converting from type
[xxxxx.service.controllers.ProfileController$1] to type
[org.neo4j.driver.Value]
Is mutating specific properties like in raw query possible in spring-data-neo4j? Please suggest a way to use property map.

Spring Data Solr: map type field

is it possible to define in #SolrDocument a field with type Map<String, List<String>>?
I've tried using:
#Indexed(name = "words", type = "string")
var words: Map<String, List<String>>?
I'm setting that field as
val words = mapOf(Pair("1111", listOf("word1", "word2"))) but when saving to Solr this field isn't saved at all. And when this document is found by SolrRepository the value for field words is null.
What type in #Indexed annotation do I have to use to get Map type?
If you are still looking for an answer:
#Field("words_*")
#Dynamic
var words: Map<String, List<String>>?
should do the trick

Unmarshal JSON to String, BigInteger and BigDecimal with jackson very close

We are using jackson, and I see this in the code
DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS
DeserializationConfig.Feature.USE_BIG_INTEGER_FOR_INTS
But how do I get jackson to use those features now?
This would be the perfect situation. I just want a Map result with String, BigDecimal and BigIntegers.
Enable the feature on the ObjectMapper.
ObjectMapper mapper = new ObjectMapper();
mapper.enable(DeserializationConfig.Feature.…);
Update for version >= 2.0.0:
ObjectMapper mapper = new ObjectMapper();
mapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
mapper.enable(DeserializationFeature.USE_BIG_INTEGER_FOR_INTS);

Deserialize option<'a>

When trying to deserialize a record member of type Header option returned from a JSON string, I get the following exception:
The data contract type
'Microsoft.FSharp.Core.FSharpOption`1[[MyWeb.Controllers.Header,
MyWeb.Controllers, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null]]' cannot be deserialized because the required
data member 'value' was not found.
I'm serializing/deserializing a Message record:
[<DataContract>]
type Header =
{ [<DataMember>] mutable ID : int
[<DataMember>] mutable Description : string }
[<DataContract>]
type Message =
{ [<DataMember>] mutable ID : int
[<DataMember>] mutable Header : Header option
[<DataMember>] mutable SenderID : string
[<DataMember>] mutable ReceiverID : string }
The code I use to deserialize the JSON:
let deserializeJson<'a> (s:string) =
use ms = new MemoryStream(ASCIIEncoding.ASCII.GetBytes s)
let serialize = DataContractJsonSerializer(typeof<'a>)
serialize.ReadObject ms :?> 'a
And the actual raw JSON result:
"Message":
{
"ID":13,
"Header": { "Value":{"ID":21,"Description":"some"}},
"SenderID":"312345332423",
"ReceiverID":"16564543423"
}
The question: how do I deserialize a 'a option?
Update
ASP.NET MVC uses JavaScriptSerializer by default to serialize objects and I'm using DataContractJsonSerializer to deserialize.
For some reason it seems DataContractJsonSerializer can't read the JSON string unless the Value property for the option is in lowercase (as pointed out by #svick). A dirty fix would be to replace "Value" with "value" in the returned JSON string, but I've chosen to go with Roberts' suggestion.
If you were to hop over to using json.net (a.k.a Newtonsoft.Json) instead of the json serializer that comes with the .NET framework, then you could use the option serializer I built to allow me to work more effectively with ravendb. Should just be a matter of registering the convert with the serializer and calling Deserialize.