How do I import a JSON file into objectbox database on Android - gson

I am receiving a JSON file which contains a number of entities that I wish to store in ObjectBox (Android). Is there a way to directly put the entire JSON tree into ObjectBox or is it necessary to convert the JSON into plain old Java objects and then save it to ObjectBox?
An option considered is to convert to entities using GSON.
User user = new User();
box.put(user);

Yes, please use Jackson or GSON to convert JSON to objects first. ObjectBox does not have direct JSON APIs.
Example:
User user = gson.fromJson(json, User.class);
userBox.put(user);
For relation support, you might want to watch this issue.

Related

How to store user data in firefox web extension

I want to store data (increasing everytime the extension is "triggered") in a json file to display it for the user. I can't find a solution on how to add a json file where I can store and overwrite data.
To store persistent data between between uses, you'll need to use the "storage" API which you can read about here.
Basically, you'll want to include the storage API in your manifest, then call it with methods like let gettingAllStorageItems = browser.storage.local.get(null);. Here's an example.

serialize an array of strings and null values

I'm using protobuf to serialize json from api for flutter app.
however I'm having an issue where I need to serialize this list for example:
"value_array": [ "",
"",
null
]
If I use the usual:
repeated string value_array = 6;
I get an exception during parsing the json.
and sadly I can't have the json changed from api. even worse I can't just manually remove the null from json before parsing it as this element in json is repeated in many different api calls.
PS. I don't need to differentiate the empty string from null, just want to avoid the exception.
thanks in advance for any help.
protobuf has a very opinionated view on JSON, and not all JSON concepts map cleanly to protobuf concepts; for example, protobuf has no notion of null
It might be fine and reasonable to use the protobuf JSON variant if you're always talking protobuf-to-protobuf and want readability (hence text over binary), but if you're working with an external (non-protobuf) JSON tool, honestly: don't use protobuf. Use any relevant JSON-specific tool for your platform - it will do a better job of handling the JSON and supporting your needs. You can always re-map that data to your protobuf model after you have deserialized it, if you need.

How can I use Parse to send data to specific user

I'm creating an online game which have to send data between users. I chose Parse as the backend service. How can I use Parse to do this task?
Query for the user that you want to send data to and send data
Take a look a the Parse Docs. What you want to do is documented very well there.
https://parse.com/docs/android_guide
Take a look at saving and retrieving objects.
Also make sure your console (where you can see the "User" class and all your other classes) is set up with the objects you need.

reading arbitrary dataset data returned from asp.net web api

I'm new to asp.net web api.
I've written a method that calls a stored procedure and gets a dataset back thru the enterprise library data access application block. I want to consume that from an asp.net webforms application (all .net 4.5/visual studio 2013). I want to be able to do this for any stored procedure I have that returns a dataset without writing a specific class for the dataset or the specific json object or whatever that I can convert it to.
I've found examples of doing this with custom classes like this:
HttpResponseMessage response = await client.GetAsync("api/products/1");
if (response.IsSuccessStatusCode)
{
Product product = await response.Content.ReadAsAsync<Product>();
}
where Product is some class representing a product.
I assume this code could be easily modified to get an ado.net DataSet instance or XML or a JSON representation of a DataSet without writing a custom class like Product to accept the data but I haven't figured that out or found it yet. An example would be good.
If you just want a string representation of the HTTPContent you can do string jsonContent = await response.Content.ReadAsStringAsync(); This will return the content in whatever string format it was serialized in by the client. With this json formatted string I assume you could read that into your ado.net dataset object.

ASP.Net Web API Help Pages: Ignore certain properties

Is it possible to have the Help Page sample generator ignore certain properties of a particular type?
For example, we use the same DTO for object Request and Response messages, for both POST and PUT requests. When user is POSTing a model (creating a new record) they don't need to provide the ID field.
But once its created and we serialize the new record into the response body, the ID field is included and returned to the client.
So in the POST request sample, I don't want the ID field to be displayed because for post request it doesn't make sense.
But the POST response sample, I do want the ID field displayed...
I am aware that there is the ApiExplorerSettings attribute which can be applied to a Class or Method...but is there anything similar for a Property?
Something like this would be great:
public class MyDTO
{
[ApiExplorerSettings(IgnoreForRequestApi = true, IgnoreForResponseApi = false)]
public int Id { get; set; }
// Other properties omitted for brevity...
}
Using the following annotation I've successfully hidden a property from the generation!
[ApiExplorerSettings(IgnoreApi = true)]
No, there isn't a similar option for a property. HelpPage uses formatter instances configured on the application to serialize the samples and as you can imagine the formatters must not have this knowledge within themselves.
Regarding workarounds:
a. You could explicitly set the raw sample for a particular action's requestsample via the SetSampleRequest extension of HttpRequestMessage. You should be able to see some examples about this in the file at *Areas\HelpPage\App_Start\HelpPageConfig.cs*.
b. In the file Areas\HelpPage\SampleGeneration\HelpPageSampleGenerator.cs, there is a method called WriteSampleObjectUsingFormatter which uses the application's formatter instances to write the samples. Here you would need to create new formatter instances having similar settings as your normal application has(so that they reflect the exact serialization/deserialization semantics that your application would normally react to when actual requests are made) and then try to hide the properties which you want to. We want to create new instances because we do not want to disturb the normal functioning of the application.
Example: In case of Json, you could create a new Json formatter instance and provide a ContractResolver which can hide the properties. Check this link: http://james.newtonking.com/projects/json/help/html/ConditionalProperties.htm
In case of Xml, I am not sure how we can hide properties without using the IgnoreDataMember attribute and also being non-intrusive.
Currently I would prefer option 'a' as its comparatively a simple workaround than 'b'.
ASP.NET WEB API uses Json.NET for JSON and DataContarctSerailizer for XML formatting so if you add [JsonIgnore] annotations over properties that you do not want included in your serialization should work just fine.

Resources