Am new to REST webservice, i have a scenario where each field in a form to be save to the database as when user fills the field.
So am calling an update API when user goes from one field to another. Using jpa for database operation. The problem am facing here is, lets say for example Employee.
{
"fname":
"lname":
"mname":
"addresses":
{
"line1":
"line2":
}
}
While user fills fname my json will be
{
"fname":"some value"
}
ill call rest to update. And for next field
{
"lname":"another value"
}
in this update case lname will be updated but fname updated with a blank value since am not passing fname. So i have to send full json to have a proper value.
Think if my json is too big with many relation, am feeling just to update one field its not good to pass complete json to the REST API's.
Can somebody give me any idea or any solution for this.
Am developing this with Spring-boot framework
Thanks in advance.
Related
I want to bulk-load some emails in the Gsuite account using a csv file. However there's this field called "building id" which is NOT REQUIRED but is handy for my requirements; I just realized that out of the box, Gsuite cannot locate a record by the mentioned field as the search term. My question is, is there a workaround to this problem? Better yet, does Gsuite support the creation of custom fields that can be used to discover information when used as search strings? Anyone who knows a solution to this problem?
When using the Directory API to list the members, using the query parameter to get the members with a specific buildingId is not an option. The available queries that can be made are listed here.
However, you can create your own custom field using the below Directory API schemas.insert request:
POST https://admin.googleapis.com/admin/directory/v1/customer/{customerId}/schemas
With the following request body:
{
"schemaId": string,
"schemaName": string,
"fields": [
{
"displayName": "",
"fieldName": "",
"fieldType": ""
}
],
"displayName": string,
}
Afterwards, when you want to retrieve the users with a particular value, you will have to make the below request:
GET https://admin.googleapis.com/admin/directory/v1/users
With the following fields:
customFieldMask > set to the name of the schema;
projection > set to custom;
query=schemaName.FIELD='VALUE' > this will query the users who have the field from the custom field with the value 'VALUE'.
Reference
Directory API Users:list;
Directory API Schemas.insert.
I am designing a MySQL database for storing profiles and user responses to questions from these profiles. Data from the database is needed to create a json objects. We are developing a REST API.
The user fills in the data (name,email, position,tel ...) and thus receives user.id. Then answers survey questions. As a result, user responses are stored in the answer table.
User's response can be prepared in advance in the options table (closed-ended questions). Or maybe not prepared (open-ended questions). Therefore, in addition to the table answer_options, which contains the user's choice of answers (many-to-many), the tableanswer contains the following fields:
text (answer to the question as text),
num (answer to the question as a number),
yn (answer to the question as a boolean type).
The table input_types contains the type of the html element (for example,<input type = "text" />.
The table insert_types contains the name of the field in the table answer (yn,text, num oroptions).
API returns questions as an JSON object:
{
"id": 1,
"label": "Annual turnover of the company?",
"placeholder": "Enter a number",
"required": true,
"input_type": {
"name": "text"
},
"insert_type": {
"name": "num"
}
}
Front-end looks at insert_type send an JSON object relying on it to answer the question:
{
"user": 1,
"question": 1,
"num": 100
}
API recives an object and saves it in the answer table (thenum property is saved in answer.num)
I don't like the fact that the front-end has to concern about insert_type. How is it customary to save user survey responses to open-ended questions?
I had a similar project before. What I did was add user's open ended answers to options table as well, and use the answer_options table for all the answer.
For the front end, it can always send the answer value without specifying the insert type. The backend can find the option_id for close ended questions, or insert the answer for open ended questions and get the option_id. Just for your reference.
I am new to spring boot and rest and hence pardon me if this question is very trivial.
I have a situation where the application allows users to register and place order.
On registration of user, the service should be able to send a response with the user information including - User Name, email, contact Number, address etc.
However, while placing orders, I would like the order response object to include within the order details, only the customer (username, email). I do not want to include the address and other information part of the User object.
Currently, what is happening is whenever, I refer to an existing user instance within the Order instance, the Order response has the complete tuple information of the registered user.
In the Order confirmation response, I really do not want the entire User information.
However, if the same Order entity is being referenced for user register, I want the service to include all fields from the Order entity.
I have tried referring to the following links -
Jackson Change JsonIgnore Dynamically
How do I exclude fields with Jackson not using annotations?
However, the solutions mentioned here will always ignore the attribute in response irrespective of the scenario in which the entity is being referenced.
For example - Response from Order service is as below.
{
"id": "ORD-1000",
"priority": null,
"status": "Open",
"customer": {
"id": "1000",
"name": "Avion Solutions",
"email": "support-na#avionsolutions.com",
"contact": null,
"customerType": "gold-sx",
"shipToContactId": null,
"billToContactId": null
},
"urgency": null
}
In the above response tuple, lets say, I just want the order information with basic customer information such as name & email.
And if the customer is registering, then the response should contain all the information as mentioned in the above tuple.
How can i dynamically ignore the attributes in response of the REST service based on the context in which the entity object is being used?
Thanks in advance.
Try to use #JsonView annotation. You can define visibility for given property and on REST Controller you can define level you want to show. For more information and examples, please, read below:
Jackson JSON Views
Jackson – Bidirectional Relationships
Using #JsonView with Spring MVC
I'm trying to create new SharePoint ListItem using Microsoft Graph.
To create a list item with simple fields like Title, my POST body looks like:
{
"fields":{
"Title":"Ehsan's REST"
}
}
But as soon as I add a field with the multichoice value I get The request is malformed or incorrect. error.
example:
{
"fields":{
"Title":"Ehsan's REST",
"Languages": ["English","French"]
}
}
During my search I found this forum post where SharePoint API (not Graph ) requires a metadata attribute to be added to the collection as an object:
"InternalFieldName":{
"__metadata":{"type":"Collection(Edm.String)"},
"results":["Value1","Value2","Value3"]
}
There's an open issue on microsoft graph doc github related to this as well.
Any suggestions?
You should be able to set the value of multi-choice columns, but you'd have to specify the type of the field to make sure OData understands it:
{
"fields": {
"choice_checkboxes#odata.type": "Collection(Edm.String)",
"choice_checkboxes":["cb1","cb2"]
}
}
I am able to post lookup column values using following:
"ProductsLookupId#odata.type": "Collection(Edm.Int32)",
"ProductsLookupId":[6,7,8]
Where Products is a lookup column to allow multiple choice.
I'm developing a web api for common CRUD operations (entities like Products, Categories) and I want to know pro/cons to suppress null properties and what should I take care choosing to ignore or not ignore these fields.
Example:
{
"name": "Product A",
"description": null
}
or
{
"name": "Product A"
}
If the client send an explict null he wants to delete the value for this property. In your first example he wants to delete the description value.
If the client does not send a property at all, he wants to leave the value of the property unchanged. In your second example he wants to leave the value of description and all other properties except name unchanged.
While you are creating new record no issues with both.But while you updating a new record if you pass null for description the record already in the db for description will be deleted, if you don't pass anything the record already in db will exist as it is.