   toJson: (aOptions)->
     result = @toJSON(aOptions)
     JSON.stringify result
+#End Value class
 
 
 module.exports = class Type

        encoding should have name property, encode and decode functions.
      '
    encoding
  constructor: (aTypeName, aOptions)->
    return super
  initialize: (aOptions)->
    defineProperty @, 'errors', null
    @_initialize aOptions if @_initialize
    @assign(aOptions)
  finalize: (aOptions)->
    @errors = null if @errors
    @encoding = null if @encoding
    @_finalize(aOptions) if @_finalize
  assign: (aOptions)->
    @errors = []
    if aOptions
      @encoding = @getEncoding aOptions.encoding
      # assign aOptions to @
      if @$attributes
        @$attributes.assignTo(aOptions, @)

    aOptions.name = @name unless aOptions.name
    @createType aOptions
  clone: @::cloneType
  # Get(create) a global Type class or create new Value from the json string.
  # it will create a new type object if options is not the original type options.
  @fromJson: (aString)->
    #aString = JSON.parse aString
    Type.from JSON.parse(aString)
