Example #1
0
    public function testComplexObject()
    {
        $writer = new JsonWriter("");
        $writer->startObjectScope();
        $writer->writeName("1");
        $writer->writeValue(2, "Edm.Int16");
        $writer->writeName("child");
        $writer->startObjectScope();
        $writer->writeName("array");
        $writer->startArrayScope();
        $writer->writeValue(100.00155, "Edm.Decimal");
        $writer->writeValue("Mar 3, 2012 11:14:32 AM", "Edm.DateTime");
        $writer->endScope();
        $writer->endScope();
        $writer->endScope();
        $expected = '{
    "1":2,"child":{
        "array":[
            "100.00155","2012-03-03T11:14:32"
        ]
    }
}';
        $this->assertEquals($expected, $writer->getJsonOutput());
    }
Example #2
0
 /**
  * serialize exception.
  *
  * @param ODataException $exception              Exception to serialize
  * @param Boolean        $serializeInnerException if set to true
  *
  * serialize the inner exception if $exception is an ODataException.
  *
  * @return string
  */
 public static function serializeException(ODataException $exception, $serializeInnerException)
 {
     $writer = new JsonWriter('');
     // Wrapper for error.
     $writer->startObjectScope()->writeName(ODataConstants::JSON_ERROR)->startObjectScope();
     // "code"
     if ($exception->getCode() != null) {
         $writer->writeName(ODataConstants::JSON_ERROR_CODE)->writeValue($exception->getCode());
     }
     // "message"
     $writer->writeName(ODataConstants::JSON_ERROR_MESSAGE)->startObjectScope()->writeName(ODataConstants::XML_LANG_ATTRIBUTE_NAME)->writeValue('en-US')->writeName(ODataConstants::JSON_ERROR_VALUE)->writeValue($exception->getMessage())->endScope()->endScope()->endScope();
     return $writer->getJsonOutput();
 }