Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
JMSSerializerBundle + FOSUserBundle with Propel
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Nick Winfield  
View profile  
 More options Oct 8 2012, 4:59 am
From: Nick Winfield <pion...@superhaggis.com>
Date: Mon, 8 Oct 2012 01:59:07 -0700 (PDT)
Local: Mon, Oct 8 2012 4:59 am
Subject: JMSSerializerBundle + FOSUserBundle with Propel

Hello,

Need a little bit of help here, because I seem to be going round in
circles.  Before I start, I have done a fair amount of research on this
issue and have tried the solutions that have been suggested in the
JMSSerializerBundle docs as well as other configuration tweaks.

Basically, I'm using FOSRestBundle to serve up an API and I chose a simple
use case to prove concept before I embark on the actual business logic.  
I'm trying to spit out JSON representing a filtered version of
\FOS\UserBundle\Propel\User but the output always contains a whole bunch of
extra fields that should have been omitted via XML configuration.

As far as I can tell, I've followed the instructions to the letter so I'm a
bit stumped.  See code below ("foo" and "bar" swapped in for actual
sensitive information)

# ./serializer/fos/Propel.User.xml
<serializer>  
    <class name="FOS\UserBundle\Propel\User" exclusion-policy="all">  
        <property name="id" type="integer" expose="true"
access-type="public_method"></property>  
        <property name="username" type="string" expose="true"
access-type="public_method"></property>  
        <property name="usernameCanonical" type="string" expose="true"
access-type="public_method"></property>  
        <property name="email" type="string" expose="true"
access-type="public_method"></property>  
        <property name="emailCanonical" type="string" expose="true"
access-type="public_method"></property>  
    </class>  
</serializer>

# ./app/config/config.yml
...

jms_serializer:
    metadata:
        directories:
            FOSUB:
                namespace_prefix: FOS\UserBundle
                path: "%kernel.root_dir%/serializer/fos"

# ./src/Foo/BarBundle/Controller/UserRestController.php
<?php

namespace Foo\BarBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class UserRestController extends Controller
{
    public function getUserAction($userId)
    {
        $user = $this->get('security.context')->getToken()->getUser();

        if ($user) {
            $view = \FOS\RestBundle\View\View::create($user, 200);
        } else {
            $view = \FOS\RestBundle\View\View::create(null, 404);
        }

        return $this->get('fos_rest.view_handler')->handle($view);
    }

}

And here's the output I'm getting - seems that all the state properties of
the Propel object are being included.

{"_new":false,"_deleted":false,"modified_columns":[],"virtual_columns":[]," start_copy":false,"id":1,"username":"foo","username_canonical":"foo","email ":"f...@bar.com","email_canonical":"f...@bar.com","enabled":true,"salt":"salt","password":"password","last_login":" 2012-10-08 09:49:38","locked":false,"expired":false,"credentials_expired":false,"alrea dy_in_save":false,"already_in_validation":false,"validation_failures":[]}

I looked in the dev cache, and there are a few files with serialized
contents corresponding to my configuration.

# ./app/cache/dev/jms_serializer/BaseObject.cache.php
# ./app/cache/dev/jms_serializer/FOS-UserBundle-Propel-om-BaseUser.cache.php
# ./app/cache/dev/jms_serializer/FOS-UserBundle-Propel-User.cache.php

Has anyone had any experience using this serializer bundle with Propel
objects before? If so, what did you do to get it working?

Thanks in advance,
Nick.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nick Winfield  
View profile  
 More options Oct 8 2012, 9:49 am
From: Nick Winfield <pion...@superhaggis.com>
Date: Mon, 8 Oct 2012 06:49:37 -0700 (PDT)
Local: Mon, Oct 8 2012 9:49 am
Subject: Re: JMSSerializerBundle + FOSUserBundle with Propel

Hello,

Well, I've made progress.  I stuck the serializer configuration into YML
(pointing at the Propel base class), stuck the file under my main bundle's
config directory (created a serializer directory) and was able to return a
filtered, serialized version of the User object.

However, I am getting additional fields coming through despite the
configuration explicitly set to "expose: false".

# ./app/config/config.yml
jms_serializer:
    metadata:
        auto_detection: true
        directories:
            fos:
                namespace_prefix: "FOS\\UserBundle"
                path: "@FooBarBundle/Resources/config/serializer"

# ./src/Foo/BarBundle/Resources/config/serializer/Propel.om.BaseUser.yml
FOS\UserBundle\Propel\om\BaseUser:
    exclusion_policy: ALL
    access_type: public_method
    properties:
        id:
            expose: true
        username:
            expose: true
        email:
            expose: true
        _new:
            expose: false
        _deleted:
            expose: false
        modified_columns:
            expose: false
        virtual_columns:
            expose: false

An example of the JSON being returned:

{"_new":false,"_deleted":false,"modified_columns":[],"virtual_columns":[]," id":1,"username":"foo","email":"f...@bar.com"}

I only want the values from the User class, not the meta properties from
Propel's base classes.  Any idea what I'm doing wrong?

Cheers,
Nick.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nick Winfield  
View profile  
 More options Oct 8 2012, 11:23 am
From: Nick Winfield <pion...@superhaggis.com>
Date: Mon, 8 Oct 2012 08:23:51 -0700 (PDT)
Local: Mon, Oct 8 2012 11:23 am
Subject: Re: JMSSerializerBundle + FOSUserBundle with Propel

Hello again,

Even though it feels like I'm talking to myself, I thought I'd share my
solution. :P

In order to get things working, however, I had to patch in the following PR
for the metadata package.

https://github.com/schmittjoh/metadata/commit/64ce1d44fd91c27c1426f21...

Basically, I had to exclude all properties accessible via public methods
from the BaseObject class in Propel.  The reason I had to patch metadata
was because the BaseObject class, where the unwanted properties reside,
does not have a namespace.

# ./app/config/config.yml
jms_serializer:
    metadata:
        auto_detection: true
        directories:
            propel:
                namespace_prefix: ""
                path: "@FooBarBundle/Resources/config/serializer"
            fos:
                namespace_prefix: "FOS\\UserBundle"
                path: "@FooBarBundle/Resources/config/serializer"

# ./src/Foo/BarBundle/Resources/config/serializer/BaseObject.yml
BaseObject:
    exclusion_policy: ALL

I cleared my dev cache and was able to view a trimmed down serialized
representation of the User object.

{"id":1,"username":"foo","email":"f...@bar.com"}

I hope my solution is of help to someone!

Cheers,
Nick.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Darryle Steplight  
View profile  
 More options Oct 8 2012, 11:50 am
From: Darryle Steplight <dstepli...@gmail.com>
Date: Mon, 8 Oct 2012 11:50:15 -0400
Local: Mon, Oct 8 2012 11:50 am
Subject: Re: [Symfony2] Re: JMSSerializerBundle + FOSUserBundle with Propel
I'm working on learning how to use JMSSerializerBundle + FOSUserBundle
to build a REST api with Symfony 2. I'll be referencing this thread if
I run into similar problems. You can rest assure that at least one
person is reading all of this.

--
----------------------------------------------
"May the Source be with you."

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richtermeister  
View profile  
 More options Nov 7 2012, 1:52 pm
From: Richtermeister <nex...@gmail.com>
Date: Wed, 7 Nov 2012 10:52:55 -0800 (PST)
Local: Wed, Nov 7 2012 1:52 pm
Subject: Re: [Symfony2] Re: JMSSerializerBundle + FOSUserBundle with Propel

Make that two :) Thanks!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
sethunath  
View profile  
 More options Nov 15 2012, 7:29 am
From: sethunath <mailse...@gmail.com>
Date: Thu, 15 Nov 2012 04:29:18 -0800 (PST)
Local: Thurs, Nov 15 2012 7:29 am
Subject: Re: JMSSerializerBundle + FOSUserBundle with Propel

Thanks for posting that


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Łukasz Blacha  
View profile  
 More options Nov 21 2012, 1:29 pm
From: Łukasz Blacha <lukasz.bla...@gmail.com>
Date: Wed, 21 Nov 2012 10:29:39 -0800 (PST)
Local: Wed, Nov 21 2012 1:29 pm
Subject: Re: JMSSerializerBundle + FOSUserBundle with Propel

Thanks :) This solution simplifies everything.

W dniu poniedziałek, 8 października 2012 10:59:07 UTC+2 użytkownik Nick
Winfield napisał:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Benjamin Meynell  
View profile  
 More options Jan 29, 5:13 pm
From: Benjamin Meynell <bmeyn...@gmail.com>
Date: Tue, 29 Jan 2013 14:13:11 -0800 (PST)
Local: Tues, Jan 29 2013 5:13 pm
Subject: Re: JMSSerializerBundle + FOSUserBundle with Propel

Nick,

Thanks for continuing to post and your eventual solution. You saved me
hours -- if not days -- of figuring this out myself.

Cheers,

Ben


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ch...@ideltd.co.uk  
View profile  
 More options Apr 15, 10:59 am
From: ch...@ideltd.co.uk
Date: Mon, 15 Apr 2013 07:59:37 -0700 (PDT)
Local: Mon, Apr 15 2013 10:59 am
Subject: Re: JMSSerializerBundle + FOSUserBundle with Propel

I too am having lots of problems using the JMSSerializer bundle with
Symfony 2.2 with Propel 1.6.9

I have a PropelObjectCollection returned from a create()->find() call and
am passing it in to the Serializer. But my json looks like this:
{

   - model: "Ide\Flirt\Model\Party",
   - formatter:
   {
      - db_name: "minxflirt",
      - class: "Ide\Flirt\Model\Party",
      - peer: "Ide\Flirt\Model\PartyPeer",
      - with: [ ],
      - as_columns: [ ],
      - has_limit: false,
      - current_objects: [ ],
      - collection_name: "PropelObjectCollection"
      }

}

Any ideas? Looking at the metadata files the patch is already in, so I've
just tried implementing the rest of your suggestions.

I can iterate around the PropelObjectCollection myself but I understood
that the JMSSerializer should do that for me. I've been back and forth
through the "official" (and very thin) documentation. If you can help with
your experience that would be great?

Thanks

Chris


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »