[Lift] Excluding a mapped field from encodeAs/decodeFromJSON

21 views
Skip to first unread message

Julian Backes

unread,
Apr 16, 2010, 2:04:15 PM4/16/10
to lif...@googlegroups.com
Hi!!

I'm trying to solve two problems with Mapper.

1) My user class (a mapper) has a field "passwordHash". This field
should not be exposed using the encodeAsJSON function. Is there an easy
way to exclude/filter fields for this function?
2) I have a field "dateCreated" which is only written once when the
object is stored in the database. Afterwards, this field should only be
read and must not be written. Again, is there an easy way to achieve
this? For example I'm using decodeFromJSON so this function should
either ignore the field or throw an error.

An optimal solution would be to only touch the mapped fields and not the
encode/decodeFromJSON functions but I don't know if this is possible.

In the documentation and in the code, I've seen some things like
"readPermission" or "writePermission" but I have no idea how they work.

Thanks in advance,
Julian

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.

Peter Robinett

unread,
Apr 16, 2010, 2:08:56 PM4/16/10
to Lift
Hi Julian,

I can't speak on the JSON issues, but for a timestamp like dateCreated
you might want to consider using the CreatedUpdated trait, since all
that functionality is already implemented:
http://www.assembla.com/wiki/show/liftweb/Mapper#createdupdated

Peter

On Apr 16, 11:04 am, Julian Backes <julianbac...@googlemail.com>
wrote:

David Pollak

unread,
Apr 16, 2010, 2:17:58 PM4/16/10
to lif...@googlegroups.com
On Fri, Apr 16, 2010 at 11:04 AM, Julian Backes <julian...@googlemail.com> wrote:
Hi!!

I'm trying to solve two problems with Mapper.

1) My user class (a mapper) has a field "passwordHash". This field should not be exposed using the encodeAsJSON function. Is there an easy way to exclude/filter fields for this function?

At this point, no, but the API is a recent addition.  Please open a ticket and mark it as a high priority to change BaseMappedField's asJsonField to return a Box (and reference this thread).  I'll make the change.
 
2) I have a field "dateCreated" which is only written once when the object is stored in the database. Afterwards, this field should only be read and must not be written. Again, is there an easy way to achieve this? For example I'm using decodeFromJSON so this function should either ignore the field or throw an error.

Please add that to the ticket and I'll add the feature.


 

An optimal solution would be to only touch the mapped fields and not the encode/decodeFromJSON functions but I don't know if this is possible.

In the documentation and in the code, I've seen some things like "readPermission" or "writePermission" but I have no idea how they work.

Thanks in advance,
Julian

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.




--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics

Julian Backes

unread,
Apr 16, 2010, 2:59:39 PM4/16/10
to lif...@googlegroups.com
Here is the ticket:
https://www.assembla.com/spaces/liftweb/tickets/477-improvements-to-mapper-to-exclude-fields-from-encodeasjson

Thank you!!

Am 16.04.10 20:17, schrieb David Pollak:
> <mailto:lif...@googlegroups.com>.
> To unsubscribe from this group, send email to
> liftweb+u...@googlegroups.com
> <mailto:liftweb%2Bunsu...@googlegroups.com>.

Julian Backes

unread,
Apr 16, 2010, 3:18:54 PM4/16/10
to lif...@googlegroups.com
Hi Peter,

thank you very much for this hint!!
Is there a way to change the column name for the mixed in fields?
Usually, I do a "overwrite def dbColumnName = ...." but this does not
seem to be possible here.
I cannot (and I don't want to) use the auto generated column names...

Julian


Am 16.04.10 20:08, schrieb Peter Robinett:

Julian Backes

unread,
Jun 15, 2010, 5:16:40 AM6/15/10
to lif...@googlegroups.com
First of all, I'm sorry to revive this old thread.
Two months ago, I asked for two changes concerning Mapper:

1) Prevent mapped fields from being exposed by encodeAsJson_!
2) Prevent mapped fields from beeing written from outside (for example a
"created" date field which is only written once when the object is
stored the first time in the database).

dpp asked me to open a ticket containing both wishes:
https://liftweb.assembla.com/spaces/liftweb/tickets/477-improvements-to-mapper-to-exclude-fields-from-encodeasjson

As far as I can judge, the first point seems to be implemented but what
about the second point?

Julian

Am 16.04.10 20:17, schrieb David Pollak:
>
>

> <mailto:lif...@googlegroups.com>.


> To unsubscribe from this group, send email to
> liftweb+u...@googlegroups.com

> <mailto:liftweb%2Bunsu...@googlegroups.com>.

David Pollak

unread,
Jun 17, 2010, 3:42:37 PM6/17/10
to lif...@googlegroups.com
On Tue, Jun 15, 2010 at 2:16 AM, Julian Backes <julian...@googlemail.com> wrote:
First of all, I'm sorry to revive this old thread.
Two months ago, I asked for two changes concerning Mapper:

1) Prevent mapped fields from being exposed by encodeAsJson_!
2) Prevent mapped fields from beeing written from outside (for example a "created" date field which is only written once when the object is stored the first time in the database).

dpp asked me to open a ticket containing both wishes:
https://liftweb.assembla.com/spaces/liftweb/tickets/477-improvements-to-mapper-to-exclude-fields-from-encodeasjson

As far as I can judge, the first point seems to be implemented but what about the second point?

MappedField.writePermission_?

have it return false and the field cannot be written.
 
Blog: http://goodstuff.im
Surf the harmonics
Reply all
Reply to author
Forward
0 new messages