lantunes / fixd

An HTTP Server Fixture for Testing HTTP Clients and mocking web services, and a Java Micro Web Framework
http://bigtesting.org/fixd
Apache License 2.0
41 stars 6 forks source link

Accessing unmarshalled entities through interpolation #20

Open lantunes opened 10 years ago

lantunes commented 10 years ago

Would it be useful to access unmarshalled entities through interpolation?

For example, a usage might be "Hello from [MyEntity.someProperty]", where MyEntity indicates that the request body should be unmarshalled using the MyEntity type, and someProperty reflectively accesses a JavaBean property called "someProperty" on the MyEntity instance. The property should have a return type, and the return value's toString() method will be invoked.

lantunes commented 10 years ago

The type MyEntity in the example above would have to be fully qualified, and given with its package name. So the example would become "Hello from [my.package.MyEntity.someProperty]". Otherwise, how could the type be resolved with just the simple name?

One option might be to provide the type to be interpolated elsewhere, such as a map, and the MyEntity type in the string could be replaced by an alias corresponding to a key in the map. So, the example could be "Hello from [entity.someProperty]", and a map would exist with {"entity" -> MyEntity.class}.

lantunes commented 10 years ago

We'd be better off using different delimiters for the bean properties. For instance, the example could become "Hello from #(entity.someProperty)", where "#(" and ")" are the delimiters.

lantunes commented 10 years ago

We could define aliases for types by registering them with the server:

server.register(MyEntity.class).withAlias("entity");

Then we can access them in the interpolated string: "Hello from #(entity.someProperty)".