logo
down
shadow

Java REST Partial Update of boolean Fields


Java REST Partial Update of boolean Fields

By : user2955612
Date : November 22 2020, 10:40 AM
hope this fix your issue I think I found the solution. Instead of using Event in Post argument, it is better to use JsonObject:
code :
...

@PUT
@Path("{id:[0-9][0-9]*}")
@Consumes(MediaType.APPLICATION_JSON)
public Response update((@PathParam("id") long id, JSONObject json) {
    Event _event = dao.find(id);

    _event.setTitle(json.optString("title"));
    _event.setFinished(json.optBoolean("finished", _event.getFinished())); // if boolean value is not provided, we don't change it

    dao.update(id, _event);
}

...


Share : facebook icon twitter icon
WCF REST API Partial update of a record

WCF REST API Partial update of a record


By : Tim Carpenter
Date : March 29 2020, 07:55 AM
it helps some times After going through various strategies of handling this kind of thing I sort of implemented what was described in the answer to this question: Only update some properties on an EF entity that are not set to null.
In a nutshell I am tracking which properties were set during desrialization and then updating only those properties.
Squeryl: how to toggle a boolean column using a partial update

Squeryl: how to toggle a boolean column using a partial update


By : Florinacho
Date : March 29 2020, 07:55 AM
hope this fix your issue I made a little code project out of your example. The problem is that squeryl serializes the update, but it "swallows" the (!), producing the following SQL:
code :
 update MyEntity set
 some_flag = (some_flag)
    // From __update, Table.scala
    val dba = Session.currentSession.databaseAdapter
    val sw = new StatementWriter(dba)
    val o0 = _callbacks.beforeUpdate(o.asInstanceOf[AnyRef]).asInstanceOf[T]
    dba.writeUpdate(o0, this, sw, checkOCC)
val s = ((entity: InsertTypeHere) =>
      where(entity.id === id)
      set(entity.some_flag := not entity.some_flag))
     class NotExpression(val ast: ExpressionNode)(implicit val mapper: OutMapper[BooleanType])
        extends PrefixOperatorNode(ast, "not ", false)
                with LogicalBoolean with NestedExpression with TypedExpressionNode[BooleanType]

     def mynot(b: BooleanExpression[BooleanType]) = new NotExpression(b)

     transaction {
          update(table)(t => where(t.id === 3) set (t.some_flag := mynot(t.some_flag)))
     }
update the nested fields in json using partial update or update queries

update the nested fields in json using partial update or update queries


By : user1748724
Date : March 29 2020, 07:55 AM
I wish this help you Your JSON has errors, I feel you should cover the strings with quotes.
A good solution to your problem is to transform the JSON to object and then transform the object back to JSON file.
code :
var  jsonT = '{"macid":"mac1234","attri":{"data":{"ch1":12,"ch2":123},"settings":{"log_time":"1min"}}}'

var f = JSON.parse(jsonT);
f.attri.data.ch1 = "hi"

jsonT = JSON.stringify(f);
console.log(jsonT);
REST: How to support create-Or-Update and partial-update ? (aka PUT vs PATCH)

REST: How to support create-Or-Update and partial-update ? (aka PUT vs PATCH)


By : Arty Shein
Date : March 29 2020, 07:55 AM
should help you out PUT and PATCH have differing message semantics, but the core context ("remote authoring") is the same. In both cases, the client request is "Please, server, make your representation of this resource match my local copy".
For example, I GET a JSON document from the server. I make local edits to it. Now I want to "save" my changes on the server. If the document is modest in size, I might just send the entire revised document over the network. If the document is very large, and my changes are modest, then I might instead send the patch instead.
REST API Update by partial json

REST API Update by partial json


By : Pran Nath
Date : March 29 2020, 07:55 AM
will help you If the Update request uses the same Customer struct then the struct fields could be pointers to differentiate between zero value and value not being set in the JSON.
Now all you need to do is merge existing struct into updated Consumer struct.
code :
package main

import (
    "fmt"
    "github.com/imdario/mergo"
    "encoding/json"
    "os"
)

type Address struct {
    City string `json:"city"`
}

type Customer struct {
    Id      int64 `json:"id"`
    Name    string `json:"name"`
    Age     int `json:"age"`
    Address *Address `json:"address"`
}


func main() {
    old1 := &Customer{Id:1, Name:"alpha", Age:5, Address:&Address{City:"Delhi"}}

    b := []byte(`{"name": "beta"}`) //no address, age specified picks from old
    up1 := new(Customer)
    json.Unmarshal(b, up1)
    if err := mergo.Merge(up1, old1); err != nil {
        fmt.Printf("err in 1st merge: %v\n", err)
        os.Exit(1)
    }
    m1, _ := json.Marshal(up1)
    fmt.Printf("merged to: %v\n", string(m1))

    old2 := &Customer{Id:1, Name:"alpha", Age:5, Address:&Address{City:"Delhi"}}
    b2 := []byte(`{ "address": {"city": "mumbai"}}`) //address specified
    up2 := new(Customer)
    json.Unmarshal(b2, up2)
    if err := mergo.Merge(up2, old2); err != nil {
        fmt.Printf("err in 1st merge: %v\n", err)
        os.Exit(1)
    }
    m2, _ := json.Marshal(up2)
    fmt.Printf("merged to: %v\n", string(m2))
}
Related Posts Related Posts :
  • Why onNext has no effect
  • IntelliJ Idea 2018.2 no option for importing gradle project
  • Remove a negative element from an array w/o array.copy
  • Could this prevent overflow in Java?
  • In Java Swing, can I receive Caret events in real time?
  • I need help not using brute force when using JFrames and DrawWindows
  • How do I refactor ArrayList<MyClass> into MyClassLIst?
  • My program keeps saying that the method cannot be resolved
  • BubbleSort -my code returns random addresses
  • JavaFX components inside HTML?
  • Character in Java game not responding
  • Working around access denied in a FileWalking Tree in Java7
  • How to avoid if/else when using multple suppliers?
  • How to pass object from table cell editor to Table Model?
  • Paypal Sandbox payment state pending
  • sejda-console.bat passing parameters with spaces
  • Multiple Consumers Spring Kafka
  • Bitbucket pipeline: environmental variables in build.gradle file not recognized
  • Java static enum method to return a default enum value
  • What is the complexity of empty for loop?
  • Group randomly List of Lists as N subsets with K elements in each
  • How to set texture on a shape drawn by glDrawArrays()?
  • How to make a jlabel resizable according to the window
  • Java Mathematical Expression Syntax
  • assigning values to characters in java
  • Method overriding and Inheritance in java
  • given a set of lists/groups with a series of number, find matching numbers
  • Connection to HID USB device (keyboard and mouse) in android
  • Inject HttpServletRequest in CDI SessionScoped bean
  • Pool game in java - ball collision algorithm
  • Focus ScrollView to selected position programmatically - Android
  • Is it hibernate bug?
  • Glib memory allocation error
  • Android Proguard - step by step
  • Setting the pivot point of a JPanel to its center
  • java check time is greater time
  • how to save a screenshot (matlab)
  • Anti-aliasing filled shapes in libgdx
  • Gwt custom text box having baloon popup
  • How to change date dynamically for each element in an Array
  • JPanel won't add the JLabel text?
  • how to access the .properties file in ant if it is in different location
  • Reduce application memory footprint
  • java.lang.ClassCastException: javax.mail.Session cannot be cast to javax.mail.Session
  • What is the exact purpose of calling System.exit() in java
  • How to do you get output from Javascript into Java using ScriptEngine
  • Java replaceAll() method to escape special characters
  • Java (Removing a 'keyword' from the alphabet)
  • Format BigDecimal in Spring
  • iterating checkbox values stored in array using EL
  • Java - Jackcess API with .accde(MS Access) format
  • Alternative for some of Struts 1 methods in Struts 2
  • javax.crypto JDK source code, again
  • Spring Roo - Command 'service' not found
  • antlr4: ATN version 2 expected 3
  • Deploy GlassFish using Netbeans generate java.net.MalformedURLException: Bad URL path
  • why is wait() called for loop in Thread.join() of Java?
  • Java JAXB marshall into DOM Document
  • Why JDBI 3 @ColumnName annotation doesn't work?
  • Java SimpleDateformatter with 10 decimals after the seconds, cannot convert to Date
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org