Skip to content
This repository was archived by the owner on Apr 5, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/main/php/webservices/rest/RestMarshalling.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,13 @@ public function marshal($value) {
}

$class= typeof($value);
$classToSearchIn= $class;
$fields= [];
do {
$fields= array_merge($fields, $classToSearchIn->getFields());
} while (($classToSearchIn= $classToSearchIn->getParentclass()) !== null);
$r= [];
foreach ($class->getFields() as $field) {
foreach ($fields as $field) {
$m= $field->getModifiers();
if ($m & MODIFIER_STATIC) {
continue;
Expand Down
8 changes: 8 additions & 0 deletions src/test/php/webservices/rest/unittest/ChildClass.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php namespace webservices\rest\unittest;

/**
* Class ChildClass
*/
class ChildClass extends ParentClassWhithPrivateFields {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php namespace webservices\rest\unittest;

use lang\Object;

/**
* Class ParentClassWhithPrivateFields
*/
class ParentClassWhithPrivateFields extends Object {

/** @var string */
private $field1;

/** @var string */
private $field2;

/**
* @return string
*/
public function getField1() {
return 'getter_'.$this->field1;
}

/**
* @param string $field1
* @return $this
*/
public function setField1($field1) {
$this->field1= $field1;
return $this;
}

/**
* @return string
*/
public function getField2() {
return 'getter_'.$this->field2;
}

/**
* @param string $field2
* @return $this
*/
public function setField2($field2) {
$this->field2= $field2;
return $this;
}



}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace webservices\rest\unittest;

use unittest\TestCase;
use webservices\rest\TypeMarshaller;
use lang\Object;
use lang\Type;
Expand All @@ -19,7 +20,7 @@
*
* @see xp://webservices.rest.RestMarshalling
*/
class RestMarshallingTest extends \unittest\TestCase {
class RestMarshallingTest extends TestCase {
private static $enumClass;
private static $walletClass;
private static $moneyMarshaller;
Expand Down Expand Up @@ -164,6 +165,20 @@ public function marshal_issue_with_field() {
);
}

#[@test]
public function marshal_parent_class_with_private_fields() {
$instance= new ChildClass();
$instance->setField1('val1');
$instance->setField2('val2');
$this->assertEquals(
[
'field1' => 'getter_val1',
'field2' => 'getter_val2'
],
$this->fixture->marshal($instance)
);
}

#[@test]
public function marshal_issue_with_getter() {
$issue= new IssueWithGetter(1, 'test');
Expand Down