Previous metadata values should be unset when updating metadata
See original GitHub issueWhen updating metadata, the other bindings (tested with Python, not sure about the others) will unset the previous metadata fields.
E.g., with the Python bindings:
>>> c = stripe.Customer.retrieve("cus_...")
>>> c.metadata
<StripeObject at 0x10577b868> JSON: {
"A": "is for Aardvark",
"B": "is for Baboon"
}
>>> c.metadata = {'C': 'is for Cactus', 'D': 'is for Dachsund'}
>>> c.save()
>>> c = stripe.Customer.retrieve("cus_...")
>>> c.metadata
<StripeObject at 0x10577b868> JSON: {
"C": "is for Cactus",
"D": "is for Dachsund"
}
The bindings correctly reset the 'A'
and 'B'
keys in the update request:
{
metadata:
{
A: "",
B: "",
C: "is for Cactus",
D: "is for Dachsund"
}
}
However, when doing the same operation with the Java bindings:
Customer customer = Customer.retrieve("cus_...");
System.out.println("Before update:");
System.out.println(customer.getMetadata());
Map<String, Object> customerParams = new HashMap<String, Object>();
Map<String, String> customerMetadata = new HashMap<String, String>();
customerMetadata.put("C", "is for Cactus");
customerMetadata.put("D", "is for Dachsund");
customerParams.put("metadata", customerMetadata);
customer.update(customerParams);
customer = Customer.retrieve("cus_...");
System.out.println("After update:");
System.out.println(customer.getMetadata());
The result is:
Before update:
{B=is for Baboon, A=is for Aardvark}
After update:
{B=is for Baboon, A=is for Aardvark, C=is for Cactus, D=is for Dachsund}
The update request only sent the new metadata keys, but didn’t reset the previously existing ones:
{
metadata:
{
C: "is for Cactus",
D: "is for Dachsund"
}
}
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Updating metadata without deleting the previous value
Question is how add next ID without erase previous. Now after every update in metafield saved last user ID, need save all ID's...
Read more >Trying to update Values in Standard Object from metaData
apex - Trying to update Values in Standard Object from metaData - Salesforce Stack Exchange. Stack Overflow for Teams – Start collaborating and ......
Read more >Create Metadata in a Space and Add it to a Page - Confluence
To add a default value to any metadata field simply edit the Metadata set(s) the field belongs in. Click on pencil symbol if...
Read more >Updating and Maintaining your Metadata - YouTube
This 20 minute webinar will provide an overview of updating, evaluating, and maintaining the metadata records you register with Crossref.
Read more >Edit Metadata: Component reference - Azure Machine Learning
Use Edit Metadata anytime you need to modify the definition of a column, typically to meet requirements for a downstream component. For example, ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is intended behavior. stripe-java objects do not implement “save” methods that take the in-memory object and persist it to the API. Instead, stripe-java objects implement an explicit update method, the contract of which is that it sends its map of parameters directly over the wire.
To unset a metadata key in stripe-java, pass empty string as the value. For instance,
customerMetadata.put("D", "");
Ah sorry didn’t realize that stripe-java overrides our handling of empty string. Thanks for catching!