-
-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an option to specify properties prefix #100
Comments
Can this be configured somehow with the current configuration options? I am interested in writing properties with a common prefix to a file. |
I could not find, a workaround: import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.dataformat.yaml.*;
import java.util.*;
public class T {
static class Test {
@JsonProperty
int field1 = 44;
}
public static Object nestObject(Object o, List<String> levels) {
if (levels.size() == 0) {
return o;
}
else {
return Collections.singletonMap(levels.get(0), nestObject(o, levels.subList(1, levels.size())));
}
}
public static Object nestObject(Object o, String... levels) {
return nestObject(o, Arrays.asList(levels));
}
public static void main(String... args) throws Exception {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
System.out.println(mapper.writeValueAsString(nestObject(new Test(), "a", "b", "c")));
}
} |
I successfully used
|
Nice, I need it mostly for reading. Of course I can read into Map<String, Object> and then convert value the value of the nested object, however, I believe this feature can be very useful. |
This sounds reasonable to me; useful thing. I would be interested in a PR -- ideally against I could see this working either via reuse of "root name" concept, or, as a new property of |
@cowtowncoder this is a draft as a base for discussion at #105 . I did not use the withRootName as it seems to me that it should be altered at core to support multiple nodes, for example for json/yaml/properties to have a nested prefix and not a single one, to resolve the problem in a generic manner. For example, I would expect to be able to produce a yaml at nested level with root prefix ["prefix1", "prefix2", "prefix3"]: prefix1:
prefix2:
prefix3:
name: Bob Please tell me what you think. |
Hi @cowtowncoder any chance you review? |
Missed this one earlier, but will add to my WIP page to hopefully review:
|
@alonbl Apologies for ultra-slow review. I think I would like to (finally!) proceed, and unless I've asked for and received it, would need CLA:
which only needs to be sent once for all contributions. Usual way is to print, fill & sign, scan, email to |
Sent, thanks!
|
Properties may contain multiple objects based on prefix, for example: a.b.c.name = a.b.c.id = x.y.z.name = x.y.z.color = To read these formats a prefix should be used as a filter when reading and as append when generating. A new optional JavaPropsSchema::prefix() and JavaPropsSchema::withPrefix() are added to control the behavior. As each path component is an object, use of ObjectReader::withRootName has a different meaning so schema property was used. PR #100
Still you can use the same trick for reading:
|
How is this supposed to work exactly? I've the following:
and when I load, let's say, a file
|
@cdprete I am not sure how what you show is in related to this issue -- issues for Java properties format backend, not YAML. |
Any plan to have it also for YAML files? |
@cdprete I don't think there is a specific plan. I think databind has a request for FasterXML/jackson-databind#512 which might cover this -- but no work done for that. It is highly voted-for fwtw. Properties input is bit different as it does not have explicit structure and comes as a sequence of key/value pairs, so applying prefix is easier. There is no theoretical reason why prefix handling could not be added to YAML backend as a one-off, at streaming level ( |
Hi,
Properties may have a prefix for an object, for example:
It would be nice if a prefix can be specified, so that only these properties with the prefix will be loaded, prefix will be stripped and then business as usual. When writing, the prefix will be added.
This will allow reading system properties and complex file properties using this interface quite easily and replace many of the complex properties processing.
If this is acceptable, I can workout a patch.
Thanks!
The text was updated successfully, but these errors were encountered: