I have followed this tutorial Make a GET Request. Now I would like to get the value of a string instead of an integer. So I adjusted the path to request.add("path", "RAW,ETH,USD,MARKET") which points to a string.
To the best of my knowledge I need to return a bytes32 to access a string which I have also changed in the fulfill function that is called after the request is made however the value of the variable i am setting is still 0x0000000000000000000000000000000000000000000000000000000000000000 which is the default value.
I have also adjusted the jobId and oracle address incase the oracle I am using does not support bytes32.
Any help would be much appreciated. Thank you in advance.
remix
Related
I'm trying to do the following:
Currently I'm using Serenity (which uses Rest Assured) to perform some API requests, and I correctly obtain the responses and treat them (getResponse.getBody blablabla), resulting in a treated String.
Now, what I want to do is "convert" that String to a Response type and treat it again.
Is that possible? I can't find any information about it.
Thanks!!
AFAIK, you cannot do this, as String type cannot be casted to Response.
I'm using the following package for JsonObject:
http://vertx.io/docs/apidocs/io/vertx/core/json/JsonObject.html
If I get a JsonObject with key 'fieldName' and I want to get its value, I have to use functions such as 'getString', 'getInteger', 'getArray' etc. I mean that I have to know in advanced the type of the value. What happens if I don't know it?
Is there any generic function of retrieving value from JsonObject without knowing its type?
Use getValue(String).
It returns an Object then you can test the type and cast accordingly.
Notes for the comments: Checking the code on GitHub, looks like the getField(String) method is present in the 2.x branch. Looks like getValue(String) is delegated to getField(String) method (see the code). As of August 2017, there's no getField(String) in the master (see the code).
While configuring mail service com.day.cq.mailer.DefaultMailService, I came to know that SMTP port should be an integer (smtp.port=I"465").
But if I try configuring using sling:OsgiConfig node, as the CRX is not providing Integer for data type (only Decimal, Double and Long), I am not able to achieve this.
Is there any alternative?
Use String type in sling:OsgiConfig node to give the smtp:port in CRX/DE. This is internally processed by DefaultMailService.
If we see the DefaultMailService implementation smtp.port is String, is processed by annotations
#Property(intValue={25})
private static final String SMTP_PORT = "smtp.port";
Sandeep is wrong, the internal representation is not String. The SMTP_PORT variable is of type String, because it holds a label and not the field value.
The actual value is of type int.
But you can set the value to Long in crx.de, because the value will be internally cast to int then.
String might also work, but I did not test that.
I've been working with MyMySQL and currently have written an API call that takes a variable number of parameters and generates a search query. I have been trying to bind the passed in parameters to protect against SQL injection, however I cannot seem to figure out how to handle a variable amount of parameters. The Bind function signature looks like:
Bind(params ...interface{})
Although I guessed both solutions wouldn't work, I tried binding each parameter one at a time in a loop, and then also tried passing in a []interface{} containing all of the parameter values.
Is there anyway to handle this solution? Struct binding wont work since I could have multiple values per each field. For instance, I could have 1 or 10 company IDs passed back to me.
Your second attempt was close to success. Build a, say var foo []interface{} containing all arguments and pass it as
Bind(foo...)
See also Passing arguments to ... parameters
I am developing ASP.Net Web API application and we are exposing a REST API for different clients. I have a problem when taking users' JSON files and converting them to Data Model classes. My JSON looks like below.
{"engagementid":1,"clientname":"fsdfs","myno":"23,45","address1":"fsd","address2":"fsdfs","city":"fsdfs","zip":"fsdf","info":"fsdfs","country":"fsdfs","currency":"NOK"}
You can see that my "myno" is sent as a string. But in my Server Data Model "myno" is a double value. So what happen here is when I send the value for "myno" as "23,45", it gets assigned to MyNo property of my Model as 2345. This is wrong, because you can see that the number has been changed because of this wrong conversion. What I simply need is to restrict this conversion. I mean, I want to send an error to Client if he sends a string for "myno" property. Since it is a double value in my Server Data Model, I want to accept only numbers from the client for this property. Which means, I want it like this.
{"myno":2345} //correct
{"myno":"2345"} //wrong. I want to send a error to user by saying, "We only accept Numbers for this value"
How do I do this?
Update:
This problem gets solved if I am using int in my server-model. I mean, if a client send a string to a property which is represented as int in my model, then it gives an error to user by saying string to int conversion can not be done.
I don't whether it is correct or not. I am just telling my suggestion according to my experience. Why can't you create a custom validation attribute and check the datatype of data.
public class IsNumberAttribute : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext context)
{
if(value.GetType() != Int)
return new ValidationResult("Only Numbers Allowed");
return null;
}
}