Skip to content

Locale deserialize 'zh-hant_CN' #1411

Closed

Description

@takeseem

zh-hant_CN will convert to zh_HANT_cn

Locale include (language, country, variant), Locale.toString() use '_' to split then {language}_{country}_({variant}_# | #){script}-{extensions}

but Jackson deserialize Locale use '-' or '_' : (
code: LocaleHandle.readResolve()

iana language-tags

zh-Hant	Chinese, in traditional script	[Mark_Davis][Mark_Davis_2]	
zh-Hant-CN	PRC Mainland Chinese in traditional script	[Mark_Davis][Mark_Davis_2]	
zh-Hant-HK	Hong Kong Chinese in traditional script	[Mark_Davis][Mark_Davis_2]	
zh-Hant-MO	Macao Chinese in traditional script	[Mark_Davis][Mark_Davis_2]	
zh-Hant-SG	Singapore Chinese in traditional script	[Mark_Davis][Mark_Davis_2]	
zh-Hant-TW	Taiwan Chinese in traditional script	[Mark_Davis][Mark_Davis_2]

rfc4647 language lookup

  Example of a Lookup Fallback Pattern

   Range to match: zh-Hant-CN-x-private1-private2
   1. zh-Hant-CN-x-private1-private2
   2. zh-Hant-CN-x-private1
   3. zh-Hant-CN
   4. zh-Hant
   5. zh
   6. (default)
	public static void main(String[] args) {
		System.out.println(new Locale("zh-hant", "CN"));
	}

in jdk1.5 -> 1.8

jdk1.5	zh-hant_CN
jdk1.6	zh-hant_CN
jdk1.7	zh-hant_CN
jdk1.8	zh-hant_CN

Activity

  1. added a commit that references this issue on Feb 28, 2018
    e7968e5
  2. added a commit that references this issue on Mar 1, 2018
  3. added a commit that references this issue on Mar 1, 2018
    844d7c7
  4. beiwei30 commented on Mar 1, 2018

    @beiwei30
    Member

    one more comments: if user starts to complain the inter-op compatibility between old dubbo version and current version, we may need to consider to rollback change 0423219, or consider to introduce a system property to control the behavior.

  5. takeseem commented on Mar 1, 2018

    @takeseem
    ContributorAuthor

    我优化了代码,英文太差直接中文:(

    commit 844d7c7

    public class LocaleHandle implements java.io.Serializable, HessianHandle {
        private String value;
    
        public LocaleHandle(String locale) {
            this.value = locale;
        }
    
        private Object readResolve() {
            if (value == null) {
                return null;
            }
    
            if (value.length() == 0) {
                return new Locale("");
            }
    
            int extStart = value.indexOf("_#");
            if (extStart != -1) value = value.substring(0, extStart);
    
            String language = value, country = "", variant = "";
            int pos1 = value.indexOf('_');
            if (pos1 != -1) {
                language = value.substring(0, pos1++);
    
                int pos2 = value.indexOf('_', pos1);
                if (pos2 == -1) {
                    country = value.substring(pos1);
                } else {
                    country = value.substring(pos1, pos2);
                    variant = value.substring(pos2 + 1);
                }
            }
            return new Locale(language, country, variant);
        }
    }
    
  6. added a commit that references this issue on Mar 1, 2018
    376806a
  7. vihunk commented on Mar 1, 2018

    @vihunk

    The code's readability needs to improve.

  8. takeseem commented on Mar 3, 2018

    @takeseem
    ContributorAuthor

    @vihunk 能否说的更加具体,比如直接在commit 376806a添加:comments。

  9. added 2 commits that reference this issue on Mar 9, 2018
    9cef66a
    f7572ab
  10. added a commit that references this issue on Apr 4, 2018
    71e04fb
  11. added 2 commits that reference this issue on Sep 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions