How to return a list of the values of all properties where the property name starts with a given prefix in JsonPath - jsonpath

I have a JSON object of the following form.
{
"prefix.key1":"val",
"prefix.key2":"val2",
......
"anotherKey":"value",
"morekeys":"value"
}
I need all the values for the properties where the property name starts with the string "prefix". Is this possible using JsonPath?

Related

Spring Data JPA not parsing response as proper JSON string

We are using Spring MVC 4.1.2 and Spring Data JPA 1.9.0. Everything works fine but when we have custom query with only selected field for a given entity then our json response does not include property name in the response, instead it just included property value.
If I correctly guess, your custom query looks like:
SELECT e.myProperty FROM Entity e [WHERE ...]
The effect of this is that you get a List<Object[]> containing only the array of property values instead of an object that has a field with the name myProperty and its value is the value in the database.
The solution is to create a custom data-transfer object, which has this one field and assign the value in the constructor
public class MyPropertyDTO { // find a better name, though :)
private int myProperty;
public MyPropertyDTO(int myProperty) {
this.myProperty = myProperty;
}
public int getMyProperty() {
return myProperty;
}
}
Then rewrite your query as:
SELECT NEW com.mycompany.MyPropertyDTO(e.myProperty) FROM Entity e [WHERE ...]
In theory you could even use your original Entity class, add a json view on myProperty and create the matching constructor instead of creating a brand new class.

how to pass multiple key/value pairs in a single variable using query string?

I have one requirement like passing multiple values in the query string in a single variable.
Id=(refine_1=cgid=womens&refine_2=c_refinementColor=Black&refine_3=price=(0..500))
Is it possible to accept value like above sample from the query string?if yes,please tel me how to achieve this?
You should URL encode it:
?id=(refine_1%3Dcgid%3Dwomens%26refine_2%3Dc_refinementColor%3DBlack%26refine_3%3Dprice%3D(0..500))
Now assuming that your controller action takes an id parameter:
public ActionResult SomeAction(string id)
{
...
}
the value of this parameter inside the action will be (refine_1=cgid=womens&refine_2=c_refinementColor=Black&refine_3=price=(0..500)).
You could bring this even a step further and write a custom model binder that will parse this value and bind it to a view model containing those properties that your controller action could take as parameter instead of a id string parameter.

In C# how to add Dynamic value in an Attribute of a property

I have the following code block: -
using System.ComponentModel.DataAnnotations;
public class NewsItem
{
[RegularExpression(System.Configuration.ConfigurationSettings.AppSettings["UrlRegEx"], ErrorMessage = "Invalid link")]
public string Url { get; set; }
}
This returns the error "An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type".
How can I give the value in the first parameter of a RegularExpression attribute. I want to give the values from Web.Config variables. I am using this code in the Model class of EF.
You can point data annotation to pick the value from resource file
See ErrorMessageResourceName
OR
You can write your custom validation method and pick the value from there
See CustomValidationAttribute
OR
You can write a regular expression derived attribute class that can reads the value from web.config.

looping through object property names in actionscript

I have a dynamic class that I have created
public dynamic class SiteZoneFileUploadVO
{
public var destination:String = "sitezone";
public var siteZoneId:uint;
public var fileType:String;
public var fileContents:String;
public function SiteZoneFileUploadVO()
{
}
}
when I try to iterate over this object's property names it only iterates the dynamically added properties.
parameters.dynVar= "value";
for(var name:String in parameters)
{
trace(name);
}
Even though the object has all the properties equal to a value (ive checked this in the debugger) the only property name that will be traced is dynVar.
How can I iterate over all the property names and not just the dynamically added ones?
You can use describeType() to get an XML with all methods and variables of your class and then filter out the properties you want to iterate over (e.g. all variables) and store them in an XMLList.
As the next step you would then iterate over the XMLList and use square bracket notation on your object to access the filtered properties by their names. However, you can only access public properties this way because describeType() won't look at private properties.
If you're running flex:
Looked at a few posts, ObjectUtil.toString was the most promising, then looked at the flex source code for it, it uses another method ObjectUtil.getClassInfo which is exactly what you need. If you just want property names:
ObjectUtil.getClassInfo(myClass).properties
returns an Array of QName objects, each has a localName property which will give you a string for each property name
Just use trace(ObjectUtil.toString(parameters)); That should give you your entire object.

asp.net mvc empty value

Can someone tell me why I get the null value for activationLink variable in the following code:
public ActionResult Activate(string activationLink)
{
if(string.IsNullOrEmpty(activationLinkROWGUID)) return View("ActivateClientError");
if (linkROWGUID != Guid.Empty)
{
return new CServerFacadeFactory().GetServerFacade.ActivateOperator(activationLinkROWGUID) ? View("ActivateClient") : View("ActivateClientError");
}
return View("ActivateClientError");
}
the link which I use is as follows : http://localhost/ActivateClient/Activate/xxxActivationLink
If you are using the default route, it expects to map the last value in the url to a parameter named id not activationLink. Either change your parameter name to id or change your routing set up to add a route that maps the value onto the correct parameter name. Changing the name of the parameter is, of course, easier.

Resources