I have a binary file containing ascii strings like {'ClassName': 'Array', 'Type': ... }, and I'd like to identify this format. It seems the file was created using Java or C++, but I cannot find which the serialization library/format. Can anybody help with this?
Related
I am trying to parse the following YAML content using Jackson in Kotlin.
template:
# More properties...
noise.max: 0.01
I get this exception:
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "noise.max" ...
When I change my YAML to this, it works:
template:
# More properties...
noise:
max: 0.01
It seems like Jackson can't parse nested values if they are noted inline with dots as separators. Is this incorrect YAML, or unconventional?
I know that spring boot can parse this kind of nested YAML params, and I guess they use Jackson for it too. But I can't find a way how I can configure the ObjectMapper so it works.
Can someone please help me an tell me how to configure ObjectMapper or whatever else needs to be done?
In YAML, a dot is not a special character and simply part of the content. The first file contains two mappings, with the inner one having noise.max as key, while the second file contains three mappings, where the innermost has max as key and the one above that has noise as key. These are different structures.
Spring boot maps YAML to Properties. It does so by concatenating nested keys via dots. If you do this, the result of both your YAML files will be:
template.noise.max = 0.01
And that is why it works with Spring boot.
Property files are a list of key/value pairs while YAML files describe a possibly complex node graph. Spring boot uses YAML as syntax sugar for Properties. If you use Jackson, you process the actual structure and not the simplified one that you get with Spring boot.
So the bottom line is: If you want to use a YAML library for loading YAML, you will not have this „feature“ of replacing nested maps with dots in keys. Theoretically you could use SnakeYAML to do some preprocessing at the event level to split such keys so that what you want is possible, but I wouldn't recommend it.
(Ctrl+Alt+Shift+I) and type Hardcoded Strings: only find the hardcoded strings in the .java files and not find strings in .kt files
Ah, well actually there's an update. Kotlin IDE does understand org.jetbrains.annotations.PropertyKey 11, but it does not always work. I have had problems if the bundle contains more than one language.
Example:
fun message(#PropertyKey(resourceBundle = "Messages") id: String) =
ResourceBundle.getBundle("Messages").getString(sid) ?: "###$id###"
For more visit:https://developer.android.com/studio/write/lint#src
I am trying to process a dataset with JSON data. However, the data have been written on a file without being parsed. That means that a python dictionary is written in the file as a string instead of a JSON object as a string.
I've found a module (AST) that will do the job to convert the string to a dictionary again using the ast.literal_eval function.
However, I am getting a very strange error in some of the instances:
The code reads from a text file and apply the following to each line:
ast.literal_eval(line.rstrip())
It seems some of the characters are not ok with the AST module.
Need to recall as well that this is not happening with all the dataset, just with some instances.
Any ideas?
Many thanks in advance.
Try exploring the json package. It is cleaner and more standard way of converting strings to dictionary
json.loads(inputStr) // Converts string -> dict
json.dumps(inputJson) // Converts dict -> string
Hope this helps. Cheers!
I need to parse Javascript object definitions using Objective C.
Note that I'm NOT deserialising JSON. I need to parse bits of actual javascript source code. For example, something like this:
{ name : "Peter", phone : "" }
Note that unlike JSON, the 'name' and 'phone' don't have to be in quotes. This causes NSJSONSerialisation to fail immediately, so pretending that it's just JSON isn't going to work.
I don't suppose anyone has a solution that doesn't involve me writing an entire parser?
I have to build a REST service with ServiceStack; the responses must have a certain format. Both JSON and XML are to be supported. The standard serializers do not return the response in the format I need.
For JSON, it would be enough to wrap the result, e.g. if a function returns a list of Site objects, the JSON serializer gives me [{...}, ...], but I need {"Sites": [{...}, ...]}. The requested content-type would be "Sites+json" in this case. For other functions, "Sites" would be replaced by something else.
How can I achieve this?
Edit:
The XML has to be the direct "translation" of the JSON, like
<Sites>...</Sites> instead of {"Sites":...}.
The standard XML serialization works differently, it always puts in the data type as well.
Has anyone an idea how to do this? I guess I have to write my own XML serializer and map all my XML types (like Sites+xml,...) to it?