2017 © Pedro PelĂĄez
 

library weasel

Object marshalling library for PHP supporting JSON and XML

image

moodev/weasel

Object marshalling library for PHP supporting JSON and XML

  • Wednesday, September 23, 2015
  • by marcgear
  • Repository
  • 5 Watchers
  • 26 Stars
  • 124,998 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 11 Forks
  • 11 Open issues
  • 15 Versions
  • 6 % Grown

The README.md

PHP Weasel

Build Status, (*1)

Weasel is an object marshalling library for PHP supporting JSON and XML. Marshalling is, by default, configured using “annotations”, driven by the Doctrine\Common\Annotation library., (*2)

It also includes its own Annotation library, Weasel\Annotation, but this is considered deprecated in favour of using Doctrine., (*3)

The latest version can be found here: https://github.com/moodev/php-weasel, (*4)

The documentation can be found here: https://github.com/moodev/php-weasel/wiki, (*5)

Installation

If you can, use composer. If you can't, you'll find the list of dependencies in composer.json., (*6)

Usage

Annotate the classes you want to serialize/deserialize (see the documentation.), (*7)

Then:, (*8)

$factory = new WeaselDoctrineAnnotationDrivenFactory();
// optionally:
    $factory->setCache($cacheInstance);
    $factory->setLogger($psr3LoggerInstance);

$mapper = $factory->getJsonMapperInstance();
$thing = $mapper->readString($json, $typeToDecodeTo);
$backToJson = $mapper->writeString($thing);

Why?

json_decode() decodes to arrays or stdObj. Weasel, while making use of json_decode() internally, maps to objects; it's basically a configuration driven Object Mapper for JSON., (*9)

Meanwhile, json_encode() gives you no fine grained control over how your data gets serialized to JSON. You can't disable marshalling of fields, you can't add typing information without adding it to your classes, and, most annoyingly, you don't have any control over how array() gets mapped on a field-by-field basis. Weasel allows you to configure how fields are marshalled on a per-field level: if you've got an array that should always be mapped as a JSON object, while other arrays need to be mapped as an array, you can have just that., (*10)

The XmlMarshaller just seemed like a good idea at the time. It probably wasn't. It's incomplete and unloved. As soon as I find a better approach to the problem, it'll be deprecated., (*11)

This project spawned from work on moo-php, a client library for the moo.com API. After writing serialization/deserialization code that was specific to that object structure, I realised that a general purpose, configurable marshaller, similar to Jackson in the Java world, would be rather useful. Weasel is the result., (*12)

The Versions

23/09 2015

dev-master

9999999-dev http://github.com/moodev/php-weasel

Object marshalling library for PHP supporting JSON and XML

  Sources   Download

ISC

The Requires

 

The Development Requires

json serialization deserialization marshalling marshall jackson

23/09 2015

dev-readme-copy-editing

dev-readme-copy-editing http://github.com/moodev/php-weasel

Object marshalling library for PHP supporting JSON and XML

  Sources   Download

ISC

The Requires

 

The Development Requires

json serialization deserialization marshalling marshall jackson

15/04 2015

v0.17

0.17.0.0 http://github.com/moodev/php-weasel

Object marshalling library for PHP supporting JSON and XML

  Sources   Download

ISC

The Requires

 

The Development Requires

json serialization deserialization marshalling marshall jackson

16/12 2014

v0.16

0.16.0.0 http://github.com/moodev/php-weasel

Object marshalling library for PHP supporting JSON and XML

  Sources   Download

ISC

The Requires

 

The Development Requires

json serialization deserialization marshalling marshall jackson

05/05 2014

0.15.2

0.15.2.0 http://github.com/moodev/php-weasel

Object marshalling library for PHP supporting JSON and XML

  Sources   Download

ISC

The Requires

 

The Development Requires

marshalling marshall

01/05 2014

v0.15.1

0.15.1.0 http://github.com/moodev/php-weasel

Object marshalling library for PHP supporting JSON and XML

  Sources   Download

ISC

The Requires

 

The Development Requires

marshalling marshall

20/06 2013

dev-lax-types

dev-lax-types http://github.com/moodev/php-weasel

Object marshalling library for PHP supporting JSON and XML

  Sources   Download

ISC

The Requires

 

The Development Requires

marshalling marshall

10/06 2013

v0.15.0

0.15.0.0 http://github.com/moodev/php-weasel

Object marshalling library for PHP supporting JSON and XML

  Sources   Download

ISC

The Requires

 

The Development Requires

marshalling marshall

25/04 2013

v0.14.1

0.14.1.0 http://github.com/moodev/php-weasel

Object marshalling library for PHP supporting JSON and XML

  Sources   Download

ISC

The Requires

 

The Development Requires

marshalling marshall

13/04 2013

v0.14.0

0.14.0.0 http://github.com/moodev/php-weasel

Object marshalling library for PHP supporting JSON and XML

  Sources   Download

ISC

The Requires

 

The Development Requires

marshalling marshall

29/03 2013

v0.13.0

0.13.0.0 http://github.com/moodev/php-weasel

Object marshalling library for PHP supporting JSON and XML

  Sources   Download

ISC

The Requires

 

The Development Requires

marshalling marshall

10/03 2013

v0.12.0

0.12.0.0 http://github.com/moodev/php-weasel

Object marshalling library for PHP supporting JSON and XML

  Sources   Download

ISC

The Requires

  • php >=5.3.0

 

marshalling marshall

11/02 2013

v0.10.0

0.10.0.0 http://github.com/moodev/php-weasel

Object marshalling library for PHP supporting JSON and XML

  Sources   Download

The Requires

  • php >=5.3.0

 

marshalling marshall

23/07 2012

v0.9.2

0.9.2.0 http://github.com/moodev/php-weasel

Object marshalling library for PHP supporting JSON and XML

  Sources   Download

The Requires

  • php >=5.3.0

 

marshalling marshall

21/07 2012

v0.9.1

0.9.1.0 http://github.com/moodev/php-weasel

Object marshalling library for PHP supporting JSON and XML

  Sources   Download

The Requires

  • php >=5.3.0

 

marshalling marshall