title: Creating different POJO child objects depending on criteria but share common fields
body: <p>I am implementing a log management system and want the types of logs to be extendible. We get a base object parsed from JSON (from Filebeat) such as:</p>
  
  <pre><code>class LogLine {
     String message
     Date timestamp
     String type
     String source
  }
  </code></pre>
  
  <p>Given this LogLine object, I want to be able to create different objects, which will also extend this LogLine.</p>
  
  <pre><code>class SomeLog extends LogLine {
      int myfield
      String username
  }
  
  class SomeOtherLog extends LogLine {
     Date startTime
     Date endTime
     String username
     String transactionID
  }
  </code></pre>
  
  <p>So, in my current non-ideal implementation:</p>
  
  <pre><code>void parse(String s){
     LogLine logLine = .....parseFromString(s)
     if ( logline.type.equals('def') ){
        SomeLog someLog = new SomeLog.Builder.build(logLine)
     } else if ( logline.message.containts('abc') ){
        SomeOtherLog someotherLog = new SomeOtherLog.Builder.build(logline)
     }
  }
  </code></pre>
  
  <p>However, as you can imagine the builders in subclasses copies the superclass LogLine object, is there anyway I can do that without copying the values as they are already subclasses? Is there a design pattern to achieve this? I would not like to rely on reflection like <code>BeanUtils.copyProperperties</code></p>