Skip to content

Commit 7bfdafe

Browse files
committed
release 1.1.2
1 parent 96bfeb7 commit 7bfdafe

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## 1.1.2
22

3-
* Issue #6 has been fixed
3+
* Issues #5, #6 has been fixed
44

55
## 1.1.1
66

lib/json_mapper.dart

+8-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ class JsonMapper {
129129
Map<String, MethodMirror> instanceMembers = classMirror.instanceMembers;
130130
return instanceMembers.values
131131
.where((MethodMirror method) {
132-
return method.isGetter && method.isSynthetic && !method.isPrivate;
132+
final isGetterAndSetter = method.isGetter &&
133+
classMirror.instanceMembers[method.simpleName + '='] != null;
134+
return (method.isGetter &&
135+
(method.isSynthetic || isGetterAndSetter)) &&
136+
!method.isPrivate;
133137
})
134138
.map((MethodMirror method) => method.simpleName)
135139
.toList();
@@ -216,7 +220,9 @@ class JsonMapper {
216220

217221
DeclarationMirror getDeclarationMirror(ClassMirror classMirror, String name) {
218222
DeclarationMirror result;
219-
result = classMirror.declarations[name] as VariableMirror;
223+
try {
224+
result = classMirror.declarations[name] as VariableMirror;
225+
} catch (error) {}
220226
if (result == null) {
221227
classMirror.instanceMembers
222228
.forEach((memberName, MethodMirror methodMirror) {

test/test.constructors.dart

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
part of json_mapper.test;
22

3+
@jsonSerializable
4+
class User {
5+
String _email;
6+
7+
String get email => _email;
8+
9+
set email(String email) => _email = email;
10+
}
11+
312
@jsonSerializable
413
class Foo {
514
final Bar bar;
@@ -20,6 +29,7 @@ class Baz {}
2029

2130
class Base<T> {
2231
final T value;
32+
2333
Base(this.value);
2434
}
2535

@@ -34,41 +44,46 @@ class Pt {
3444
}
3545

3646
@jsonSerializable
37-
class PtDerived extends Base<Pt>{
47+
class PtDerived extends Base<Pt> {
3848
PtDerived(Pt value) : super(value);
3949
}
4050

4151
@jsonSerializable
4252
class StringListClass {
4353
List<String> list;
54+
4455
StringListClass(this.list);
4556
}
4657

4758
@jsonSerializable
4859
class PositionalParametersClass {
4960
String firstName;
5061
String lastName;
62+
5163
PositionalParametersClass(this.firstName, this.lastName);
5264
}
5365

5466
@jsonSerializable
5567
class OptionalParametersClass {
5668
String firstName;
5769
String lastName;
70+
5871
OptionalParametersClass([this.firstName, this.lastName]);
5972
}
6073

6174
@jsonSerializable
6275
class PartiallyOptionalParametersClass {
6376
String firstName;
6477
String lastName;
78+
6579
PartiallyOptionalParametersClass(this.firstName, [this.lastName]);
6680
}
6781

6882
@jsonSerializable
6983
class NamedParametersClass {
7084
String firstName;
7185
String lastName;
86+
7287
NamedParametersClass({this.firstName, this.lastName});
7388
}
7489

@@ -158,6 +173,16 @@ testConstructors() {
158173
expect(pTargetJson, '{"value":{}}');
159174
});
160175

176+
test("User class, getter/setter property w/o constructor", () {
177+
// given
178+
final User user = User();
179+
user.email = '[email protected]';
180+
// when
181+
final json = JsonMapper.serialize(user, '');
182+
// then
183+
expect(json, '{"email":"[email protected]"}');
184+
});
185+
161186
test("StringListClass class", () {
162187
// given
163188
// when

0 commit comments

Comments
 (0)