Browse Source

fix: Ignore if field does not exist

master
Krrish Ghimire 5 years ago
parent
commit
8fc1410cd0
  1. 56
      LICENSE
  2. 5
      src/np/com/krrish/Mapper.java
  3. 4
      test/np/com/krrish/Destination.java
  4. 6
      test/np/com/krrish/MapperTest.java
  5. 6
      test/np/com/krrish/Source.java

56
LICENSE

@ -109,7 +109,7 @@ work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion. menu, a prominent item in the list meets this criterion.
1. Source Code. 1. np.com.krrish.Source Code.
The "source code" for a work means the preferred form of the work The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source for making modifications to it. "Object code" means any non-source
@ -131,24 +131,24 @@ implementation is available to the public in source code form. A
(if any) on which the executable work runs, or a compiler used to (if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it. produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all The "Corresponding np.com.krrish.Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source which are not part of the work. For example, Corresponding np.com.krrish.Source
includes interface definition files associated with source files for includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require, linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those such as by intimate data communication or control flow between those
subprograms and other parts of the work. subprograms and other parts of the work.
The Corresponding Source need not include anything that users The Corresponding np.com.krrish.Source need not include anything that users
can regenerate automatically from other parts of the Corresponding can regenerate automatically from other parts of the Corresponding
Source. np.com.krrish.Source.
The Corresponding Source for a work in source code form is that The Corresponding np.com.krrish.Source for a work in source code form is that
same work. same work.
2. Basic Permissions. 2. Basic Permissions.
@ -205,7 +205,7 @@ recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey, You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee. and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions. 5. Conveying Modified np.com.krrish.Source Versions.
You may convey a work based on the Program, or the modifications to You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the produce it from the Program, in the form of source code under the
@ -242,16 +242,16 @@ beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other in an aggregate does not cause this License to apply to the other
parts of the aggregate. parts of the aggregate.
6. Conveying Non-Source Forms. 6. Conveying Non-np.com.krrish.Source Forms.
You may convey a covered work in object code form under the terms You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License, machine-readable Corresponding np.com.krrish.Source under the terms of this License,
in one of these ways: in one of these ways:
a) Convey the object code in, or embodied in, a physical product a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the (including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium Corresponding np.com.krrish.Source fixed on a durable physical medium
customarily used for software interchange. customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product b) Convey the object code in, or embodied in, a physical product
@ -259,39 +259,39 @@ in one of these ways:
written offer, valid for at least three years and valid for as written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the copy of the Corresponding np.com.krrish.Source for all the software in the
product that is covered by this License, on a durable physical product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge. Corresponding np.com.krrish.Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This written offer to provide the Corresponding np.com.krrish.Source. This
alternative is allowed only occasionally and noncommercially, and alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord only if you received the object code with such an offer, in accord
with subsection 6b. with subsection 6b.
d) Convey the object code by offering access from a designated d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no Corresponding np.com.krrish.Source in the same way through the same place at no
further charge. You need not require recipients to copy the further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to Corresponding np.com.krrish.Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source copy the object code is a network server, the Corresponding np.com.krrish.Source
may be on a different server (operated by you or a third party) may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the Corresponding np.com.krrish.Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is Corresponding np.com.krrish.Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements. available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no np.com.krrish.Source of the work are being offered to the general public at no
charge under subsection 6d. charge under subsection 6d.
A separable portion of the object code, whose source code is excluded A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be from the Corresponding np.com.krrish.Source as a System Library, need not be
included in conveying the object code work. included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any A "User Product" is either (1) a "consumer product", which means any
@ -310,7 +310,7 @@ the only significant mode of use of the product.
"Installation Information" for a User Product means any methods, "Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must a modified version of its Corresponding np.com.krrish.Source. The information must
suffice to ensure that the continued functioning of the modified object suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because code is in no case prevented or interfered with solely because
modification has been made. modification has been made.
@ -320,7 +320,7 @@ specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied Corresponding np.com.krrish.Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has modified object code on the User Product (for example, the work has
@ -334,7 +334,7 @@ network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and adversely affects the operation of the network or violates the rules and
protocols for communication across the network. protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided, Corresponding np.com.krrish.Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in documented (and with an implementation available to the public in
source code form), and must require no special password or key for source code form), and must require no special password or key for
@ -457,7 +457,7 @@ work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if Corresponding np.com.krrish.Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts. the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the You may not impose any further restrictions on the exercise of the
@ -497,10 +497,10 @@ party means to make such an agreement or commitment not to enforce a
patent against the party. patent against the party.
If you convey a covered work, knowingly relying on a patent license, If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone and the Corresponding np.com.krrish.Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means, publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so then you must either (1) cause the Corresponding np.com.krrish.Source to be so
available, or (2) arrange to deprive yourself of the benefit of the available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent consistent with the requirements of this License, to extend the patent
@ -631,7 +631,7 @@ to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found. the "copyright" line and a pointer to where the full notice is found.
Object Mapper Object np.com.krrish.Mapper
Copyright (C) 2019 krrishg Copyright (C) 2019 krrishg
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode: notice like this when it starts in an interactive mode:
Object Mapper Copyright (C) 2019 krrishg Object np.com.krrish.Mapper Copyright (C) 2019 krrishg
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details. under certain conditions; type `show c' for details.

5
src/Mapper.java → src/np/com/krrish/Mapper.java

@ -1,3 +1,5 @@
package np.com.krrish;
import java.lang.reflect.*; import java.lang.reflect.*;
public class Mapper { public class Mapper {
@ -13,8 +15,9 @@ public class Mapper {
destinationField.setAccessible(true); destinationField.setAccessible(true);
destinationField.set(object, sourceField.get(source)); destinationField.set(object, sourceField.get(source));
} }
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException | NoSuchFieldException e) { } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace(); e.printStackTrace();
} catch (NoSuchFieldException ignored) {
} }
return object; return object;
} }

4
test/Destination.java → test/np/com/krrish/Destination.java

@ -1,8 +1,10 @@
package np.com.krrish;
public class Destination { public class Destination {
private String first; private String first;
private String second; private String second;
public String getFirst() { String getFirst() {
return first; return first;
} }

6
test/MapperTest.java → test/np/com/krrish/MapperTest.java

@ -1,3 +1,5 @@
package np.com.krrish;
import org.junit.jupiter.api.*; import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
@ -13,7 +15,7 @@ class MapperTest {
@Test @Test
void testEmptyFieldsMap() { void testEmptyFieldsMap() {
Source source = new Source(); Source source = new Source();
Object destination = mapper.map(source, "Destination"); Object destination = mapper.map(source, "np.com.krrish.Destination");
assertEquals(Destination.class, destination.getClass()); assertEquals(Destination.class, destination.getClass());
} }
@ -23,7 +25,7 @@ class MapperTest {
source.setFirst("first"); source.setFirst("first");
source.setSecond("second"); source.setSecond("second");
Destination destination = (Destination) mapper.map(source, "Destination"); Destination destination = (Destination) mapper.map(source, "np.com.krrish.Destination");
assertEquals("first", destination.getFirst()); assertEquals("first", destination.getFirst());
} }
} }

6
test/Source.java → test/np/com/krrish/Source.java

@ -1,12 +1,14 @@
package np.com.krrish;
public class Source { public class Source {
private String first; private String first;
private String second; private String second;
public void setFirst(String first) { void setFirst(String first) {
this.first = first; this.first = first;
} }
public void setSecond(String second) { void setSecond(String second) {
this.second = second; this.second = second;
} }
} }
Loading…
Cancel
Save