JMSSerializerBundle icon indicating copy to clipboard operation
JMSSerializerBundle copied to clipboard

New Feature: support multiple configurations

Open rkmax opened this issue 10 years ago • 5 comments

Currently I need to use the serializer differently at one point in my application, would be excellent if we can declare a default serializer and others with different configurations

Example currently my configuration is

jms_serializer:
    enable_short_alias:   true
    handlers:
        datetime:
            default_format:       'Y-m-d\TH:i:sO'
            default_timezone:     America/Bogota
            cdata:                true

maybe can be

jms_serializer:
    default:
        enable_short_alias:   true
        handlers:
            datetime:
                default_format:       'Y-m-d\TH:i:sO'
                default_timezone:     America/Bogota
                cdata:                true
    simple:
        handlers:
            datetime:
                default_format:       'Y-m-d'
                default_timezone:     America/Bogota
                cdata:                true

in the code

$container->get('serializer'); // return default handler alias to 'serializer_default'
$container->get('serializer_simple') ; // return simple handler

rkmax avatar Nov 20 '14 12:11 rkmax

Should the timezone be stored in the context instead? this will make it even more flexible

goetas avatar Mar 29 '17 10:03 goetas

I have a similar scenario. I some parts of my project I want to use one peculiar visitors configuration:

jms_serializer:
  unescaped:    
      visitors:
          json:
              options: JSON_UNESCAPED_SLASHES

In order to have some serializations with unescaped strings and other with escaped ones (needed for backward compatibility).

Is it possible to achieve this without multiple configurations?

andreij avatar Sep 19 '17 09:09 andreij

currently is not possible

goetas avatar Sep 19 '17 09:09 goetas

My application interact with two 3rd party services. First service have snake_cased fields, second have camelCased fields. It would be great to have multiple serializer configurations.

xtix avatar Oct 11 '21 15:10 xtix

see https://github.com/schmittjoh/JMSSerializerBundle/pull/831

goetas avatar Oct 13 '21 07:10 goetas