How would I convert IniPreferences to a Map in Java?
I currently have
public static Map<String, String> configMap;
Ini ini = new Ini(configIni);
java.util.prefs.Preferences prefs = new IniPreferences(ini);
configMap = new HashMap<>();
configMap.put("Version", prefs.node("Settings").get("Version", null));
However this would require me to insert the key for anything added to the ini making it a pain to maintain.
The prefs.node will always be settings however preferably they would be combined into configMap.
How would I automate this?
Related
I am playing with Stripe-Java and I'm trying to add a card to a customer.
My code looks like this:
Customer stripeCustomer = Customer.retrieve("cus_xxxxxxx");
Map<String, Object> cardParam = new HashMap<String, Object>();
cardParam.put("number", "4242424242424242");
cardParam.put("exp_month", "11");
cardParam.put("exp_year", "2022");
cardParam.put("cvc", "123");
//token
Map<String, Object> tokenParam = new HashMap<String, Object>();
tokenParam.put("card", cardParam);
Token token = Token.create(tokenParam);
//user token
Map<String, Object> sourceParam = new HashMap<String, Object>();
sourceParam.put("source", token.getId());
//add to customer
stripeCustomer.getSources().create(sourceParam);
This works successfully on Stripe-Java version 19.45.0 but not on 20.0.0 or any versions above. Has the method to add a card changed?
A nullpointer exception is thrown
Thanks
This : stripeCustomer.getSources() will be null in v20.0.0 and above of the library because it pins to API version 2020-08-27 where customer.sources was removed by default. [0] [1]
The sources property on Customers is no longer included by default.
You can expand the list but for performance reasons we recommended
against doing so unless needed.
You would need to explicitly expand [2] "sources" when retrieving the Customer in order to populate customer.getSources()
CustomerRetrieveParams params = CustomerRetrieveParams.builder()
.addExpand("sources").build();
Customer stripeCustomer = Customer.retrieve("cus_xxxxxxx", params, null);
Also, your code uses the legacy Token API, and is passing raw card details from your server that puts you in PCI scope, you should look into the recommended integration paths : https://stripe.com/docs/payments/accept-a-payment
[0] https://github.com/stripe/stripe-java/blob/master/CHANGELOG.md#2000---2020-08-31
[1] https://stripe.com/docs/upgrades#2020-08-27
[2] https://stripe.com/docs/expand
I want to create a map of type Map> in spring boot , below is the thing i configured in my application.yml and related java class
labels:
nodetypes:
payment:
- customerId
- emailId
- movileNumber
profile:
loyality:
#Data
#ConfigurationProperties(prefix = "labels")
#Component
public class NodeTypeToResponseProps {
Map<String, List<String>> nodetypes = new HashMap<>();
}
but map is not creating , i am expecting , a map will get created with below data in it
{payment : [customerId,emailId,movileNumber] ,profile:[] ,loyality:[] }
any help on this please ?
Thanks to everyone , who tried to help me in solving the issue , i found the solution for this plugin in my build.gradle
id 'io.freefair.lombok' version '3.8.4'
it is working fine now .
You have to create Arraylists int this YAML configuration which has the name of the attributes. Than your essential able to call your Object by only calling the attribute.
Example:
YamlConfiguration yaml = new YamlConfiguration();
HashMap<String, List<String>> nodetypes = new HashMap<>();
//setter
for(String key :nodetypes.keySet())
yaml.set("path."+key, nodetypes.get(key));
yaml.set("path."+new String("keys"), nodetypes.keySet());
//getter
HashMap<String, List<String>> cp = new HashMap<>();
for(String key:yaml.getStringList("path."+new String("keys")))
cp.put(key, yaml.getStringList("path."+key));
You can trying put #Component before that #ConrigurationProerties
I am trying to automatically assign a ticket using JRJC 4.0.0.
I am using this:
final Map<String, FieldInput> map = new HashMap<>();
map.put("assignee", new FieldInput("assignee", "XXXX"));
a_conn.getIssueClient().updateIssue(this.m_key, new IssueInput(map)).claim();
But I get this error:
[ErrorCollection{status=400, errors={assignee=data was not an object}, errorMessages=[]}]
Anyone already know the solution? I tried searching here in SO but can't find anything that works.
final IssueInputBuilder is = new IssueInputBuilder();
is.setAssigneeName(a_username);
a_conn.getIssueClient().updateIssue(this.m_key, is.build()).claim();
I'm building an Nativesctipt app for Android that uses Firebase as backend and I'm using the native Firebase Android library v2.4.0
I can insert objects in Firebase just fine using the following {N} Javascript syntax
var user = new java.util.HashMap();
user.put("name", viewModel.get("name"));
user.put("lastName", viewModel.get("lastName");
var address = new java.util.HashMap();
address.put("address", viewModel.get("address");
address.put("number", viewModel.get("number");
address.put("city", viewModel.get("city");
user.put("address", address);
ref = new Firebase("https://my-firebase-app-url/users");
refUser = ref.child(viewModel.get("username"));
refUser.setValue(user);
The problem with this is that I have to manually convert every javascript object into a java hashSet (and back) and I wanted to do it using a JSON to HashMap library so I have imported the java Jackson library into my {N} app.
According to this site here's the way to convert a JSON to a HashMap in Java using Jackson:
ObjectMapper mapper = new ObjectMapper();
String json = "{\"name\":\"mkyong\", \"age\":29}";
Map<String, Object> map = new HashMap<String, Object>();
// convert JSON string to Map
map = mapper.readValue(json, new TypeReference<Map<String, String>>(){});
I'm looking for a way to translate that into a {N} Javascript code that will do it for me but I'm unable to use generics notation in {N} Javascript. Does anybody know how I could do it? I have tried some ways but all of them crashed the application. Here's an {N} Javascript snippet does not work:
var ObjectMapper = com.fasterxml.jackson.databind.ObjectMapper;
var TypeReference = com.fasterxml.jackson.core.type.TypeReference;
var mapper = new ObjectMapper();
var map = mapper.readValue(JSON.stringify(user), new TypeReference());
refUser.setValue(map);
Any help is greatly appreciated.
I have a template like this in properties file: Dear xxxxxx, you are payment is succesfull.
After loading this template from properties file, I want to replace that "xxxxxx" with dynamic data in Java class.
Please help me on this.
I used Message.format("template",object array which is having dynamic data);
Try this way
placeholderReplacementMap is map that contain your static value and dynamic value key pair
Map<String, Object> placeholderReplacementMap = new HashMap<>();
StrSubstitutor substitutor = new StrSubstitutor(placeholderReplacementMap);
placeholderReplacementMap.put("xxxxxx", dynamicValue);
String newString = substitutor.replace("Dear xxxxxx","you are payment is succesful");